BlueGit

blue-star danique-bot

Files

danique-bot / node_modules / minimist / readme.markdown

readme.markdown

Import template
timfa Tim · pushed by timfa · 4 years ago
c788ad20 History
readme.markdown 1.6 KiB Download Raw

minimist

parse argument options

This module is the guts of optimist's argument parser without all the fanciful decoration.

browser support

build status

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 booleans
  • opts.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
3parse argument options
4
5This module is the guts of optimist's argument parser without all the
6fanciful decoration.
7
8[![browser support](https://ci.testling.com/substack/minimist.png)](http://ci.testling.com/substack/minimist)
9
10[![build status](https://secure.travis-ci.org/substack/minimist.png)](http://travis-ci.org/substack/minimist)
11
12# example
13
14``` js
15var argv = require('minimist')(process.argv.slice(2));
16console.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
39var parseArgs = require('minimist')
40```
41
42## var argv = parseArgs(args, opts={})
43
44Return 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
47them.
48
49Numeric-looking arguments will be returned as numbers unless `opts.string` or
50`opts.boolean` is set for that argument name.
51
52Any arguments after `'--'` will not be parsed and will end up in `argv._`.
53
54options can be:
55
56* `opts.string` - a string or array of strings argument names to always treat as
57strings
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
60argument names to use as aliases
61* `opts.default` - an object mapping string argument names to default values
62
63# install
64
65With [npm](https://npmjs.org) do:
66
67```
68npm install minimist
69```
70
71# license
72
73MIT