UNPKG

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