Skip to content

Minimist-inspired option parser that cares about the order

License

Notifications You must be signed in to change notification settings

eush77/opt-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm

opt-array

Build Status Dependency Status

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 value false;
  • -- 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

About

Minimist-inspired option parser that cares about the order

Resources

License

Stars

Watchers

Forks

Packages

No packages published