committed by
GitHub
parent
20d2b4f98d
commit
e4f3964f67
215
node_modules/yargs-parser/README.md
generated
vendored
215
node_modules/yargs-parser/README.md
generated
vendored
@ -1,15 +1,15 @@
|
||||
# yargs-parser
|
||||
|
||||
[](https://travis-ci.org/yargs/yargs-parser)
|
||||

|
||||
[](https://www.npmjs.com/package/yargs-parser)
|
||||
[](https://github.com/conventional-changelog/standard-version)
|
||||
|
||||
[](https://conventionalcommits.org)
|
||||

|
||||
|
||||
The mighty option parser used by [yargs](https://github.com/yargs/yargs).
|
||||
|
||||
visit the [yargs website](http://yargs.js.org/) for more examples, and thorough usage instructions.
|
||||
|
||||
<img width="250" src="https://raw.githubusercontent.com/yargs/yargs-parser/master/yargs-logo.png">
|
||||
<img width="250" src="https://raw.githubusercontent.com/yargs/yargs-parser/main/yargs-logo.png">
|
||||
|
||||
## Example
|
||||
|
||||
@ -18,37 +18,81 @@ npm i yargs-parser --save
|
||||
```
|
||||
|
||||
```js
|
||||
var argv = require('yargs-parser')(process.argv.slice(2))
|
||||
const argv = require('yargs-parser')(process.argv.slice(2))
|
||||
console.log(argv)
|
||||
```
|
||||
|
||||
```sh
|
||||
node example.js --foo=33 --bar hello
|
||||
```console
|
||||
$ node example.js --foo=33 --bar hello
|
||||
{ _: [], foo: 33, bar: 'hello' }
|
||||
```
|
||||
|
||||
_or parse a string!_
|
||||
|
||||
```js
|
||||
var argv = require('yargs-parser')('--foo=99 --bar=33')
|
||||
const argv = require('yargs-parser')('--foo=99 --bar=33')
|
||||
console.log(argv)
|
||||
```
|
||||
|
||||
```sh
|
||||
```console
|
||||
{ _: [], foo: 99, bar: 33 }
|
||||
```
|
||||
|
||||
Convert an array of mixed types before passing to `yargs-parser`:
|
||||
|
||||
```js
|
||||
var parse = require('yargs-parser')
|
||||
const parse = require('yargs-parser')
|
||||
parse(['-f', 11, '--zoom', 55].join(' ')) // <-- array to string
|
||||
parse(['-f', 11, '--zoom', 55].map(String)) // <-- array of strings
|
||||
```
|
||||
|
||||
## Deno Example
|
||||
|
||||
As of `v19` `yargs-parser` supports [Deno](https://github.com/denoland/deno):
|
||||
|
||||
```typescript
|
||||
import parser from "https://deno.land/x/yargs_parser/deno.ts";
|
||||
|
||||
const argv = parser('--foo=99 --bar=9987930', {
|
||||
string: ['bar']
|
||||
})
|
||||
console.log(argv)
|
||||
```
|
||||
|
||||
## ESM Example
|
||||
|
||||
As of `v19` `yargs-parser` supports ESM (_both in Node.js and in the browser_):
|
||||
|
||||
**Node.js:**
|
||||
|
||||
```js
|
||||
import parser from 'yargs-parser'
|
||||
|
||||
const argv = parser('--foo=99 --bar=9987930', {
|
||||
string: ['bar']
|
||||
})
|
||||
console.log(argv)
|
||||
```
|
||||
|
||||
**Browsers:**
|
||||
|
||||
```html
|
||||
<!doctype html>
|
||||
<body>
|
||||
<script type="module">
|
||||
import parser from "https://unpkg.com/yargs-parser@19.0.0/browser.js";
|
||||
|
||||
const argv = parser('--foo=99 --bar=9987930', {
|
||||
string: ['bar']
|
||||
})
|
||||
console.log(argv)
|
||||
</script>
|
||||
</body>
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### require('yargs-parser')(args, opts={})
|
||||
### parser(args, opts={})
|
||||
|
||||
Parses command line arguments returning a simple mapping of keys and values.
|
||||
|
||||
@ -130,15 +174,15 @@ var parsed = parser(['--no-dice'], {
|
||||
|
||||
Should a group of short-options be treated as boolean flags?
|
||||
|
||||
```sh
|
||||
node example.js -abc
|
||||
```console
|
||||
$ node example.js -abc
|
||||
{ _: [], a: true, b: true, c: true }
|
||||
```
|
||||
|
||||
_if disabled:_
|
||||
|
||||
```sh
|
||||
node example.js -abc
|
||||
```console
|
||||
$ node example.js -abc
|
||||
{ _: [], abc: true }
|
||||
```
|
||||
|
||||
@ -149,15 +193,15 @@ node example.js -abc
|
||||
|
||||
Should hyphenated arguments be expanded into camel-case aliases?
|
||||
|
||||
```sh
|
||||
node example.js --foo-bar
|
||||
```console
|
||||
$ node example.js --foo-bar
|
||||
{ _: [], 'foo-bar': true, fooBar: true }
|
||||
```
|
||||
|
||||
_if disabled:_
|
||||
|
||||
```sh
|
||||
node example.js --foo-bar
|
||||
```console
|
||||
$ node example.js --foo-bar
|
||||
{ _: [], 'foo-bar': true }
|
||||
```
|
||||
|
||||
@ -168,15 +212,15 @@ node example.js --foo-bar
|
||||
|
||||
Should keys that contain `.` be treated as objects?
|
||||
|
||||
```sh
|
||||
node example.js --foo.bar
|
||||
```console
|
||||
$ node example.js --foo.bar
|
||||
{ _: [], foo: { bar: true } }
|
||||
```
|
||||
|
||||
_if disabled:_
|
||||
|
||||
```sh
|
||||
node example.js --foo.bar
|
||||
```console
|
||||
$ node example.js --foo.bar
|
||||
{ _: [], "foo.bar": true }
|
||||
```
|
||||
|
||||
@ -187,18 +231,37 @@ node example.js --foo.bar
|
||||
|
||||
Should keys that look like numbers be treated as such?
|
||||
|
||||
```sh
|
||||
node example.js --foo=99.3
|
||||
```console
|
||||
$ node example.js --foo=99.3
|
||||
{ _: [], foo: 99.3 }
|
||||
```
|
||||
|
||||
_if disabled:_
|
||||
|
||||
```sh
|
||||
node example.js --foo=99.3
|
||||
```console
|
||||
$ node example.js --foo=99.3
|
||||
{ _: [], foo: "99.3" }
|
||||
```
|
||||
|
||||
### parse positional numbers
|
||||
|
||||
* default: `true`
|
||||
* key: `parse-positional-numbers`
|
||||
|
||||
Should positional keys that look like numbers be treated as such.
|
||||
|
||||
```console
|
||||
$ node example.js 99.3
|
||||
{ _: [99.3] }
|
||||
```
|
||||
|
||||
_if disabled:_
|
||||
|
||||
```console
|
||||
$ node example.js 99.3
|
||||
{ _: ['99.3'] }
|
||||
```
|
||||
|
||||
### boolean negation
|
||||
|
||||
* default: `true`
|
||||
@ -206,15 +269,15 @@ node example.js --foo=99.3
|
||||
|
||||
Should variables prefixed with `--no` be treated as negations?
|
||||
|
||||
```sh
|
||||
node example.js --no-foo
|
||||
```console
|
||||
$ node example.js --no-foo
|
||||
{ _: [], foo: false }
|
||||
```
|
||||
|
||||
_if disabled:_
|
||||
|
||||
```sh
|
||||
node example.js --no-foo
|
||||
```console
|
||||
$ node example.js --no-foo
|
||||
{ _: [], "no-foo": true }
|
||||
```
|
||||
|
||||
@ -233,15 +296,15 @@ a configuration file.
|
||||
|
||||
Should arguments be coerced into an array when duplicated:
|
||||
|
||||
```sh
|
||||
node example.js -x 1 -x 2
|
||||
```console
|
||||
$ node example.js -x 1 -x 2
|
||||
{ _: [], x: [1, 2] }
|
||||
```
|
||||
|
||||
_if disabled:_
|
||||
|
||||
```sh
|
||||
node example.js -x 1 -x 2
|
||||
```console
|
||||
$ node example.js -x 1 -x 2
|
||||
{ _: [], x: 2 }
|
||||
```
|
||||
|
||||
@ -252,15 +315,15 @@ node example.js -x 1 -x 2
|
||||
|
||||
Should array arguments be coerced into a single array when duplicated:
|
||||
|
||||
```sh
|
||||
node example.js -x 1 2 -x 3 4
|
||||
```console
|
||||
$ node example.js -x 1 2 -x 3 4
|
||||
{ _: [], x: [1, 2, 3, 4] }
|
||||
```
|
||||
|
||||
_if disabled:_
|
||||
|
||||
```sh
|
||||
node example.js -x 1 2 -x 3 4
|
||||
```console
|
||||
$ node example.js -x 1 2 -x 3 4
|
||||
{ _: [], x: [[1, 2], [3, 4]] }
|
||||
```
|
||||
|
||||
@ -271,16 +334,16 @@ node example.js -x 1 2 -x 3 4
|
||||
|
||||
Should arrays consume more than one positional argument following their flag.
|
||||
|
||||
```sh
|
||||
node example --arr 1 2
|
||||
{ _[], arr: [1, 2] }
|
||||
```console
|
||||
$ node example --arr 1 2
|
||||
{ _: [], arr: [1, 2] }
|
||||
```
|
||||
|
||||
_if disabled:_
|
||||
|
||||
```sh
|
||||
node example --arr 1 2
|
||||
{ _[2], arr: [1] }
|
||||
```console
|
||||
$ node example --arr 1 2
|
||||
{ _: [2], arr: [1] }
|
||||
```
|
||||
|
||||
**Note: in `v18.0.0` we are considering defaulting greedy arrays to `false`.**
|
||||
@ -299,15 +362,15 @@ Should nargs consume dash options as well as positional arguments.
|
||||
|
||||
The prefix to use for negated boolean variables.
|
||||
|
||||
```sh
|
||||
node example.js --no-foo
|
||||
```console
|
||||
$ node example.js --no-foo
|
||||
{ _: [], foo: false }
|
||||
```
|
||||
|
||||
_if set to `quux`:_
|
||||
|
||||
```sh
|
||||
node example.js --quuxfoo
|
||||
```console
|
||||
$ node example.js --quuxfoo
|
||||
{ _: [], foo: false }
|
||||
```
|
||||
|
||||
@ -320,15 +383,15 @@ Should unparsed flags be stored in `--` or `_`.
|
||||
|
||||
_If disabled:_
|
||||
|
||||
```sh
|
||||
node example.js a -b -- x y
|
||||
```console
|
||||
$ node example.js a -b -- x y
|
||||
{ _: [ 'a', 'x', 'y' ], b: true }
|
||||
```
|
||||
|
||||
_If enabled:_
|
||||
|
||||
```sh
|
||||
node example.js a -b -- x y
|
||||
```console
|
||||
$ node example.js a -b -- x y
|
||||
{ _: [ 'a' ], '--': [ 'x', 'y' ], b: true }
|
||||
```
|
||||
|
||||
@ -341,15 +404,15 @@ Should a placeholder be added for keys not set via the corresponding CLI argumen
|
||||
|
||||
_If disabled:_
|
||||
|
||||
```sh
|
||||
node example.js -a 1 -c 2
|
||||
```console
|
||||
$ node example.js -a 1 -c 2
|
||||
{ _: [], a: 1, c: 2 }
|
||||
```
|
||||
|
||||
_If enabled:_
|
||||
|
||||
```sh
|
||||
node example.js -a 1 -c 2
|
||||
```console
|
||||
$ node example.js -a 1 -c 2
|
||||
{ _: [], a: 1, b: undefined, c: 2 }
|
||||
```
|
||||
|
||||
@ -362,15 +425,15 @@ Should parsing stop at the first positional argument? This is similar to how e.g
|
||||
|
||||
_If disabled:_
|
||||
|
||||
```sh
|
||||
node example.js -a run b -x y
|
||||
```console
|
||||
$ node example.js -a run b -x y
|
||||
{ _: [ 'b' ], a: 'run', x: 'y' }
|
||||
```
|
||||
|
||||
_If enabled:_
|
||||
|
||||
```sh
|
||||
node example.js -a run b -x y
|
||||
```console
|
||||
$ node example.js -a run b -x y
|
||||
{ _: [ 'b', '-x', 'y' ], a: 'run' }
|
||||
```
|
||||
|
||||
@ -383,15 +446,15 @@ Should aliases be removed before returning results?
|
||||
|
||||
_If disabled:_
|
||||
|
||||
```sh
|
||||
node example.js --test-field 1
|
||||
```console
|
||||
$ node example.js --test-field 1
|
||||
{ _: [], 'test-field': 1, testField: 1, 'test-alias': 1, testAlias: 1 }
|
||||
```
|
||||
|
||||
_If enabled:_
|
||||
|
||||
```sh
|
||||
node example.js --test-field 1
|
||||
```console
|
||||
$ node example.js --test-field 1
|
||||
{ _: [], 'test-field': 1, testField: 1 }
|
||||
```
|
||||
|
||||
@ -405,15 +468,15 @@ Should dashed keys be removed before returning results? This option has no effe
|
||||
|
||||
_If disabled:_
|
||||
|
||||
```sh
|
||||
node example.js --test-field 1
|
||||
```console
|
||||
$ node example.js --test-field 1
|
||||
{ _: [], 'test-field': 1, testField: 1 }
|
||||
```
|
||||
|
||||
_If enabled:_
|
||||
|
||||
```sh
|
||||
node example.js --test-field 1
|
||||
```console
|
||||
$ node example.js --test-field 1
|
||||
{ _: [], testField: 1 }
|
||||
```
|
||||
|
||||
@ -427,18 +490,24 @@ configured in `opts`.
|
||||
|
||||
_If disabled_
|
||||
|
||||
```sh
|
||||
node example.js --unknown-option --known-option 2 --string-option --unknown-option2
|
||||
```console
|
||||
$ node example.js --unknown-option --known-option 2 --string-option --unknown-option2
|
||||
{ _: [], unknownOption: true, knownOption: 2, stringOption: '', unknownOption2: true }
|
||||
```
|
||||
|
||||
_If enabled_
|
||||
|
||||
```sh
|
||||
node example.js --unknown-option --known-option 2 --string-option --unknown-option2
|
||||
```console
|
||||
$ node example.js --unknown-option --known-option 2 --string-option --unknown-option2
|
||||
{ _: ['--unknown-option'], knownOption: 2, stringOption: '--unknown-option2' }
|
||||
```
|
||||
|
||||
## Supported Node.js Versions
|
||||
|
||||
Libraries in this ecosystem make a best effort to track
|
||||
[Node.js' release schedule](https://nodejs.org/en/about/releases/). Here's [a
|
||||
post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).
|
||||
|
||||
## Special Thanks
|
||||
|
||||
The yargs project evolves from optimist and minimist. It owes its
|
||||
|
Reference in New Issue
Block a user