README
Valon Args
Typescript node argument parser with strong types.
Installation
# npm
npm install valon-args
# Yarn
yarn add valon-args
Example
import { cliArgs } from 'valon-args'
const options = cliArgs({
name: 'string',
retries: 'number?',
force: 'boolean',
})
// All args are now typed and validated.
options.name // string
options.retires // number | undefined
options.force // boolean | undefined
Documentation
import { cliArgs } from 'valon-args'
// Console args are automaticly parsed fron the terminal.
const args = cliArgs({ name: 'string?' })
Supported types
Input Type | Typescript type |
---|---|
string | string |
string? | string | undefined |
string[] | string[] |
number | number |
number? | number | undefined |
number[] | number[] |
boolean | boolean | undefined |
Usage
String
node ./example.js --string=foo // 'foo'
node ./example.js --string="foo bar" // 'foo bar'
String[]
node ./example.js --string=foo --string=bar // ['foo', 'bar']
node ./example.js --string="foo bar" --string="bar baz" // ['foo bar', 'bar baz']
node ./example.js --string "foo bar" foobar "bar baz" // ['foo bar', 'foobar', 'bar baz']
Number
node ./example.js --number=1 // 1
Number[]
node ./example.js --number=1 --number=2 // [1, 2]
Boolean
node ./example.js --force // true
node ./example.js --force=true // true
node ./example.js --force=false // false
node ./example.js --force=1 // true
node ./example.js --force=0 // false
node ./example.js // undefined