README
opt-array
The minimal option parser that returns options in array, so that you can process your options in the order they appear in.
If you don't really care about the order, you are better off using minimist.
Supported formats:
-abc
— multiple short options merged into a single argument;-a value
— short option with value;-n2
— short option with numeric value, merged into a single argument;--long-option
— long option;--long-option value
— long option with value;--long-option=value
— long option with value as a single argument;--no-long-option
— long option with valuefalse
;-- other args
— arguments after--
are not recognized as options.
Example
var optArray = require('opt-array');
optArray(['-abc', '-i', 'file', '4', '-n2', '--no-verbose', '--depth=4', '--', '-s', 'A'])
//=> [{ option: 'a', value: true },
// { option: 'b', value: true },
// { option: 'c', value: true },
// { option: 'i', value: 'file' },
// { value: '4' },
// { option: 'n', value: 2 },
// { option: 'verbose', value: false },
// { option: 'depth', value: 4 },
// { value: '-s' },
// { value: 'A' }]
API
optv = optArray(argv)
Returns array of options and positional arguments.
Each entry may have the following keys:
{
option: 'name', // string, for options only
value: 'value' // string, number (for numeric-looking options), true, or false
}
Install
npm install opt-array
License
MIT