JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 23
  • Score
    100M100P100Q52673F
  • License MIT

Command line arguments parser

Package Exports

  • argentum

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (argentum) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Argentum

Build Coverage Status

Argentum is a unified command line arguments parser. It parses arguments into JS values boolean, number, date, string or array of values. Argentum has no schema like other parsers it just try to parse all passed values.

It has several rules to parse values:

  • Rule could be --name, --name=value, --name[] and --name[]=value.
  • Kebab case converts into camel case --some-name becomes someName.
  • Empty property value is true: --bool mean true.
  • Arrays overwrite previous value: --arr=1 --arr[] has empty array with name arr.

Note that parsed values pull out from passed array.

Example

Argentum converts command line arguments into appropriate JS types.

node app.js --host=localhost --port=8080 --dirs[] public build

Result of parsing is:

{
  host: 'localhost',
  port: 8080,
  dirs: ['public', 'build']
}

Usage

var argentum = require('argentum');

// Parsing
argentum.parse(['--hello=world']); // -> {hello: "world"}

// Splicing
var args = ['-x', 'value', '-d'];
argentum.parse(args); // -> {x: true, d: true}
args; // -> ['value']

Parsing schema

Cli JavaScript
-v {v: true}
--hello=world {hello: 'world'}
--number=1 {number: 1}
--bool {bool: true}
--a[] 1 2 {a: [1,2]}
--a[]=1 --a[]=2 {a: [1,2]}

Interface

Package require interface.

parse(string[]) -> object

Parse array of strings and return an object of properties.

parseValue(string) -> boolean|number|string

Parse string value to match true, false or number patterns otherwise return string.

split(args string[],limit number) -> string[][]

Split array into two arrays with double hyphen as separator. Limit should match count of found separators.