Gathering detailed insights and metrics for yargs-parser
Gathering detailed insights and metrics for yargs-parser
Gathering detailed insights and metrics for yargs-parser
Gathering detailed insights and metrics for yargs-parser
@types/yargs-parser
TypeScript definitions for yargs-parser
yargs-promise
Use the headless yargs parser with promises
base-argv
Plugin that post-processes the object returned from [yargs-parser] so that values can be passed over to base-cli
process-yargs-parser
Lightweight Node.js arguments parser with 0 Dependencies 🚀. **process-yargs-parser** is an opinionated yargs-parser with many needless yargs-parser configurations disabled by default.
npm install yargs-parser
95.8
Supply Chain
99.6
Quality
79.9
Maintenance
100
Vulnerability
100
License
yargs-parser: v21.1.1
Published on 04 Aug 2022
yargs-parser: v21.1.0
Published on 03 Aug 2022
yargs-parser: v21.0.1
Published on 27 Feb 2022
yargs-parser yargs-parser-v21.0.0
Published on 16 Nov 2021
yargs-parser yargs-parser-v20.2.9
Published on 20 Jun 2021
yargs-parser yargs-parser-v20.2.8
Published on 20 Jun 2021
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
496 Stars
361 Commits
118 Forks
10 Watching
39 Branches
58 Contributors
Updated on 19 Nov 2024
JavaScript (68.26%)
TypeScript (31.4%)
HTML (0.35%)
Cumulative downloads
Total Downloads
Last day
-8.7%
19,686,478
Compared to previous day
Last week
1.3%
116,665,759
Compared to previous week
Last month
15.3%
474,887,586
Compared to previous month
Last year
7.4%
4,775,234,828
Compared to previous year
23
The mighty option parser used by yargs.
visit the yargs website for more examples, and thorough usage instructions.
1npm i yargs-parser --save
1const argv = require('yargs-parser')(process.argv.slice(2)) 2console.log(argv)
1$ node example.js --foo=33 --bar hello 2{ _: [], foo: 33, bar: 'hello' }
or parse a string!
1const argv = require('yargs-parser')('--foo=99 --bar=33') 2console.log(argv)
1{ _: [], foo: 99, bar: 33 }
Convert an array of mixed types before passing to yargs-parser
:
1const parse = require('yargs-parser') 2parse(['-f', 11, '--zoom', 55].join(' ')) // <-- array to string 3parse(['-f', 11, '--zoom', 55].map(String)) // <-- array of strings
As of v19
yargs-parser
supports Deno:
1import parser from "https://deno.land/x/yargs_parser/deno.ts"; 2 3const argv = parser('--foo=99 --bar=9987930', { 4 string: ['bar'] 5}) 6console.log(argv)
As of v19
yargs-parser
supports ESM (both in Node.js and in the browser):
Node.js:
1import parser from 'yargs-parser' 2 3const argv = parser('--foo=99 --bar=9987930', { 4 string: ['bar'] 5}) 6console.log(argv)
Browsers:
1<!doctype html> 2<body> 3 <script type="module"> 4 import parser from "https://unpkg.com/yargs-parser@19.0.0/browser.js"; 5 6 const argv = parser('--foo=99 --bar=9987930', { 7 string: ['bar'] 8 }) 9 console.log(argv) 10 </script> 11</body>
Parses command line arguments returning a simple mapping of keys and values.
expects:
args
: a string or array of strings representing the options to parse.opts
: provide a set of hints indicating how args
should be parsed:
opts.alias
: an object representing the set of aliases for a key: {alias: {foo: ['f']}}
.opts.array
: indicate that keys should be parsed as an array: {array: ['foo', 'bar']}
.{array: [{ key: 'foo', boolean: true }, {key: 'bar', number: true}]}
.opts.boolean
: arguments should be parsed as booleans: {boolean: ['x', 'y']}
.opts.coerce
: provide a custom synchronous function that returns a coerced value from the argument provided
(or throws an error). For arrays the function is called only once for the entire array:{coerce: {foo: function (arg) {return modifiedArg}}}
.opts.config
: indicate a key that represents a path to a configuration file (this file will be loaded and parsed).opts.configObjects
: configuration objects to parse, their properties will be set as arguments:{configObjects: [{'x': 5, 'y': 33}, {'z': 44}]}
.opts.configuration
: provide configuration options to the yargs-parser (see: configuration).opts.count
: indicate a key that should be used as a counter, e.g., -vvv
= {v: 3}
.opts.default
: provide default values for keys: {default: {x: 33, y: 'hello world!'}}
.opts.envPrefix
: environment variables (process.env
) with the prefix provided should be parsed.opts.narg
: specify that a key requires n
arguments: {narg: {x: 2}}
.opts.normalize
: path.normalize()
will be applied to values set to this key.opts.number
: keys should be treated as numbers.opts.string
: keys should be treated as strings (even if they resemble a number -x 33
).returns:
obj
: an object representing the parsed value of args
key/value
: key value pairs for each argument and their aliases._
: an array representing the positional arguments.--
: an array with arguments after the end-of-options flag --
.Parses a command line string, returning detailed information required by the yargs engine.
expects:
args
: a string or array of strings representing options to parse.opts
: provide a set of hints indicating how args
, inputs are identical to require('yargs-parser')(args, opts={})
.returns:
argv
: an object representing the parsed value of args
key/value
: key value pairs for each argument and their aliases._
: an array representing the positional arguments.--
: an array with arguments after the end-of-options flag --
.error
: populated with an error object if an exception occurred during parsing.aliases
: the inferred list of aliases built by combining lists in opts.alias
.newAliases
: any new aliases added via camel-case expansion:
boolean
: { fooBar: true }
defaulted
: any new argument created by opts.default
, no aliases included.
boolean
: { foo: true }
configuration
: given by default settings and opts.configuration
.The yargs-parser applies several automated transformations on the keys provided
in args
. These features can be turned on and off using the configuration
field
of opts
.
1var parsed = parser(['--no-dice'], { 2 configuration: { 3 'boolean-negation': false 4 } 5})
true
.short-option-groups
.Should a group of short-options be treated as boolean flags?
1$ node example.js -abc 2{ _: [], a: true, b: true, c: true }
if disabled:
1$ node example.js -abc 2{ _: [], abc: true }
true
.camel-case-expansion
.Should hyphenated arguments be expanded into camel-case aliases?
1$ node example.js --foo-bar 2{ _: [], 'foo-bar': true, fooBar: true }
if disabled:
1$ node example.js --foo-bar 2{ _: [], 'foo-bar': true }
true
dot-notation
Should keys that contain .
be treated as objects?
1$ node example.js --foo.bar 2{ _: [], foo: { bar: true } }
if disabled:
1$ node example.js --foo.bar 2{ _: [], "foo.bar": true }
true
parse-numbers
Should keys that look like numbers be treated as such?
1$ node example.js --foo=99.3 2{ _: [], foo: 99.3 }
if disabled:
1$ node example.js --foo=99.3 2{ _: [], foo: "99.3" }
true
parse-positional-numbers
Should positional keys that look like numbers be treated as such.
1$ node example.js 99.3 2{ _: [99.3] }
if disabled:
1$ node example.js 99.3 2{ _: ['99.3'] }
true
boolean-negation
Should variables prefixed with --no
be treated as negations?
1$ node example.js --no-foo 2{ _: [], foo: false }
if disabled:
1$ node example.js --no-foo 2{ _: [], "no-foo": true }
false
combine-arrays
Should arrays be combined when provided by both command line arguments and a configuration file.
true
duplicate-arguments-array
Should arguments be coerced into an array when duplicated:
1$ node example.js -x 1 -x 2 2{ _: [], x: [1, 2] }
if disabled:
1$ node example.js -x 1 -x 2 2{ _: [], x: 2 }
true
flatten-duplicate-arrays
Should array arguments be coerced into a single array when duplicated:
1$ node example.js -x 1 2 -x 3 4 2{ _: [], x: [1, 2, 3, 4] }
if disabled:
1$ node example.js -x 1 2 -x 3 4 2{ _: [], x: [[1, 2], [3, 4]] }
true
greedy-arrays
Should arrays consume more than one positional argument following their flag.
1$ node example --arr 1 2 2{ _: [], arr: [1, 2] }
if disabled:
1$ node example --arr 1 2 2{ _: [2], arr: [1] }
Note: in v18.0.0
we are considering defaulting greedy arrays to false
.
false
nargs-eats-options
Should nargs consume dash options as well as positional arguments.
no-
negation-prefix
The prefix to use for negated boolean variables.
1$ node example.js --no-foo 2{ _: [], foo: false }
if set to quux
:
1$ node example.js --quuxfoo 2{ _: [], foo: false }
false
.populate--
Should unparsed flags be stored in --
or _
.
If disabled:
1$ node example.js a -b -- x y 2{ _: [ 'a', 'x', 'y' ], b: true }
If enabled:
1$ node example.js a -b -- x y 2{ _: [ 'a' ], '--': [ 'x', 'y' ], b: true }
false
.set-placeholder-key
.Should a placeholder be added for keys not set via the corresponding CLI argument?
If disabled:
1$ node example.js -a 1 -c 2 2{ _: [], a: 1, c: 2 }
If enabled:
1$ node example.js -a 1 -c 2 2{ _: [], a: 1, b: undefined, c: 2 }
false
.halt-at-non-option
.Should parsing stop at the first positional argument? This is similar to how e.g. ssh
parses its command line.
If disabled:
1$ node example.js -a run b -x y 2{ _: [ 'b' ], a: 'run', x: 'y' }
If enabled:
1$ node example.js -a run b -x y 2{ _: [ 'b', '-x', 'y' ], a: 'run' }
false
strip-aliased
Should aliases be removed before returning results?
If disabled:
1$ node example.js --test-field 1 2{ _: [], 'test-field': 1, testField: 1, 'test-alias': 1, testAlias: 1 }
If enabled:
1$ node example.js --test-field 1 2{ _: [], 'test-field': 1, testField: 1 }
false
strip-dashed
Should dashed keys be removed before returning results? This option has no effect if
camel-case-expansion
is disabled.
If disabled:
1$ node example.js --test-field 1 2{ _: [], 'test-field': 1, testField: 1 }
If enabled:
1$ node example.js --test-field 1 2{ _: [], testField: 1 }
false
unknown-options-as-args
Should unknown options be treated like regular arguments? An unknown option is one that is not
configured in opts
.
If disabled
1$ node example.js --unknown-option --known-option 2 --string-option --unknown-option2 2{ _: [], unknownOption: true, knownOption: 2, stringOption: '', unknownOption2: true }
If enabled
1$ node example.js --unknown-option --known-option 2 --string-option --unknown-option2 2{ _: ['--unknown-option'], knownOption: 2, stringOption: '--unknown-option2' }
Libraries in this ecosystem make a best effort to track Node.js' release schedule. Here's a post on why we think this is important.
The yargs project evolves from optimist and minimist. It owes its existence to a lot of James Halliday's hard work. Thanks substack beep boop \o/
ISC
The latest stable version of the package.
Stable Version
4
5.3/10
Summary
yargs-parser Vulnerable to Prototype Pollution
Affected Versions
>= 16.0.0, < 18.1.1
Patched Versions
18.1.1
5.3/10
Summary
yargs-parser Vulnerable to Prototype Pollution
Affected Versions
<= 5.0.0
Patched Versions
5.0.1
5.3/10
Summary
yargs-parser Vulnerable to Prototype Pollution
Affected Versions
>= 6.0.0, < 13.1.2
Patched Versions
13.1.2
5.3/10
Summary
yargs-parser Vulnerable to Prototype Pollution
Affected Versions
>= 14.0.0, < 15.0.1
Patched Versions
15.0.1
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 8/15 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More