1 | # minimist <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
|
2 |
|
3 | [![github actions][actions-image]][actions-url]
|
4 | [![coverage][codecov-image]][codecov-url]
|
5 | [![License][license-image]][license-url]
|
6 | [![Downloads][downloads-image]][downloads-url]
|
7 |
|
8 | [![npm badge][npm-badge-png]][package-url]
|
9 |
|
10 | parse argument options
|
11 |
|
12 | This module is the guts of optimist's argument parser without all the
|
13 | fanciful decoration.
|
14 |
|
15 | # example
|
16 |
|
17 | ``` js
|
18 | var argv = require('minimist')(process.argv.slice(2));
|
19 | console.log(argv);
|
20 | ```
|
21 |
|
22 | ```
|
23 | $ node example/parse.js -a beep -b boop
|
24 | { _: [], a: 'beep', b: 'boop' }
|
25 | ```
|
26 |
|
27 | ```
|
28 | $ node example/parse.js -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
|
29 | { _: [ 'foo', 'bar', 'baz' ],
|
30 | x: 3,
|
31 | y: 4,
|
32 | n: 5,
|
33 | a: true,
|
34 | b: true,
|
35 | c: true,
|
36 | beep: 'boop' }
|
37 | ```
|
38 |
|
39 | # security
|
40 |
|
41 | Previous versions had a prototype pollution bug that could cause privilege
|
42 | escalation in some circumstances when handling untrusted user input.
|
43 |
|
44 | Please use version 1.2.6 or later:
|
45 |
|
46 | * https://security.snyk.io/vuln/SNYK-JS-MINIMIST-2429795 (version <=1.2.5)
|
47 | * https://snyk.io/vuln/SNYK-JS-MINIMIST-559764 (version <=1.2.3)
|
48 |
|
49 | # methods
|
50 |
|
51 | ``` js
|
52 | var parseArgs = require('minimist')
|
53 | ```
|
54 |
|
55 | ## var argv = parseArgs(args, opts={})
|
56 |
|
57 | Return an argument object `argv` populated with the array arguments from `args`.
|
58 |
|
59 | `argv._` contains all the arguments that didn't have an option associated with
|
60 | them.
|
61 |
|
62 | Numeric-looking arguments will be returned as numbers unless `opts.string` or
|
63 | `opts.boolean` is set for that argument name.
|
64 |
|
65 | Any arguments after `'--'` will not be parsed and will end up in `argv._`.
|
66 |
|
67 | options can be:
|
68 |
|
69 | * `opts.string` - a string or array of strings argument names to always treat as
|
70 | strings
|
71 | * `opts.boolean` - a boolean, string or array of strings to always treat as
|
72 | booleans. if `true` will treat all double hyphenated arguments without equal signs
|
73 | as boolean (e.g. affects `--foo`, not `-f` or `--foo=bar`)
|
74 | * `opts.alias` - an object mapping string names to strings or arrays of string
|
75 | argument names to use as aliases
|
76 | * `opts.default` - an object mapping string argument names to default values
|
77 | * `opts.stopEarly` - when true, populate `argv._` with everything after the
|
78 | first non-option
|
79 | * `opts['--']` - when true, populate `argv._` with everything before the `--`
|
80 | and `argv['--']` with everything after the `--`. Here's an example:
|
81 |
|
82 | ```
|
83 | > require('./')('one two three -- four five --six'.split(' '), { '--': true })
|
84 | { _: [ 'one', 'two', 'three' ],
|
85 | '--': [ 'four', 'five', '--six' ] }
|
86 | ```
|
87 |
|
88 | Note that with `opts['--']` set, parsing for arguments still stops after the
|
89 | `--`.
|
90 |
|
91 | * `opts.unknown` - a function which is invoked with a command line parameter not
|
92 | defined in the `opts` configuration object. If the function returns `false`, the
|
93 | unknown option is not added to `argv`.
|
94 |
|
95 | # install
|
96 |
|
97 | With [npm](https://npmjs.org) do:
|
98 |
|
99 | ```
|
100 | npm install minimist
|
101 | ```
|
102 |
|
103 | # license
|
104 |
|
105 | MIT
|
106 |
|
107 | [package-url]: https://npmjs.org/package/minimist
|
108 | [npm-version-svg]: https://versionbadg.es/minimistjs/minimist.svg
|
109 | [npm-badge-png]: https://nodei.co/npm/minimist.png?downloads=true&stars=true
|
110 | [license-image]: https://img.shields.io/npm/l/minimist.svg
|
111 | [license-url]: LICENSE
|
112 | [downloads-image]: https://img.shields.io/npm/dm/minimist.svg
|
113 | [downloads-url]: https://npm-stat.com/charts.html?package=minimist
|
114 | [codecov-image]: https://codecov.io/gh/minimistjs/minimist/branch/main/graphs/badge.svg
|
115 | [codecov-url]: https://app.codecov.io/gh/minimistjs/minimist/
|
116 | [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/minimistjs/minimist
|
117 | [actions-url]: https://github.com/minimistjs/minimist/actions
|
118 |
|
\ | No newline at end of file |