minimist
parse argument options
This module is the guts of optimist's argument parser without all the fanciful decoration.
example
var argv = require('minimist')(process.argv.slice(2));
console.dir(argv);
$ node example/parse.js -a beep -b boop
{ _: [], a: 'beep', b: 'boop' }
$ node example/parse.js -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
{ _: [ 'foo', 'bar', 'baz' ],
x: 3,
y: 4,
n: 5,
a: true,
b: true,
c: true,
beep: 'boop' }
methods
var parseArgs = require('minimist')
var argv = parseArgs(args, opts={})
Return an argument object argv populated with the array arguments from args.
argv._ contains all the arguments that didn't have an option associated with them.
Numeric-looking arguments will be returned as numbers unless opts.string or opts.boolean is set for that argument name.
Any arguments after '--' will not be parsed and will end up in argv._.
options can be:
opts.string- a string or array of strings argument names to always treat as
strings
opts.boolean- a string or array of strings to always treat as booleansopts.alias- an object mapping string names to strings or arrays of string
argument names to use as aliases
opts.default- an object mapping string argument names to default values
install
With npm do:
npm install minimist
license
MIT
Source
| 1 | # minimist |
| 2 | |
| 3 | parse argument options |
| 4 | |
| 5 | This module is the guts of optimist's argument parser without all the |
| 6 | fanciful decoration. |
| 7 | |
| 8 | [](http://ci.testling.com/substack/minimist) |
| 9 | |
| 10 | [](http://travis-ci.org/substack/minimist) |
| 11 | |
| 12 | # example |
| 13 | |
| 14 | ``` js |
| 15 | var argv = require('minimist')(process.argv.slice(2)); |
| 16 | console.dir(argv); |
| 17 | ``` |
| 18 | |
| 19 | ``` |
| 20 | $ node example/parse.js -a beep -b boop |
| 21 | { _: [], a: 'beep', b: 'boop' } |
| 22 | ``` |
| 23 | |
| 24 | ``` |
| 25 | $ node example/parse.js -x 3 -y 4 -n5 -abc --beep=boop foo bar baz |
| 26 | { _: [ 'foo', 'bar', 'baz' ], |
| 27 | x: 3, |
| 28 | y: 4, |
| 29 | n: 5, |
| 30 | a: true, |
| 31 | b: true, |
| 32 | c: true, |
| 33 | beep: 'boop' } |
| 34 | ``` |
| 35 | |
| 36 | # methods |
| 37 | |
| 38 | ``` js |
| 39 | var parseArgs = require('minimist') |
| 40 | ``` |
| 41 | |
| 42 | ## var argv = parseArgs(args, opts={}) |
| 43 | |
| 44 | Return an argument object `argv` populated with the array arguments from `args`. |
| 45 | |
| 46 | `argv._` contains all the arguments that didn't have an option associated with |
| 47 | them. |
| 48 | |
| 49 | Numeric-looking arguments will be returned as numbers unless `opts.string` or |
| 50 | `opts.boolean` is set for that argument name. |
| 51 | |
| 52 | Any arguments after `'--'` will not be parsed and will end up in `argv._`. |
| 53 | |
| 54 | options can be: |
| 55 | |
| 56 | * `opts.string` - a string or array of strings argument names to always treat as |
| 57 | strings |
| 58 | * `opts.boolean` - a string or array of strings to always treat as booleans |
| 59 | * `opts.alias` - an object mapping string names to strings or arrays of string |
| 60 | argument names to use as aliases |
| 61 | * `opts.default` - an object mapping string argument names to default values |
| 62 | |
| 63 | # install |
| 64 | |
| 65 | With [npm](https://npmjs.org) do: |
| 66 | |
| 67 | ``` |
| 68 | npm install minimist |
| 69 | ``` |
| 70 | |
| 71 | # license |
| 72 | |
| 73 | MIT |

