package
Converts back a yargs argv object to its original array form
npm install yargs-unparserGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Converts back a yargs argv object to its original array form.
Probably the unparser word doesn't even exist, but it sounds nice and goes well with yargs-parser.
The code originally lived in MOXY's GitHub but was later moved here for discoverability.
$ npm install yargs-unparser
const parse = require('yargs-parser');
const unparse = require('yargs-unparser');
const argv = parse(['--no-boolean', '--number', '4', '--string', 'foo'], {
boolean: ['boolean'],
number: ['number'],
string: ['string'],
});
// { boolean: false, number: 4, string: 'foo', _: [] }
const unparsedArgv = unparse(argv);
// ['--no-boolean', '--number', '4', '--string', 'foo'];The second argument of unparse accepts an options object:
alias: The aliases so that duplicate options aren't generateddefault: The default values so that the options with default values are omittedcommand: The command first argument so that command names and positional arguments are handled correctlycommand optionsconst yargs = require('yargs');
const unparse = require('yargs-unparser');
const argv = yargs
.command('my-command <positional>', 'My awesome command', (yargs) =>
yargs
.option('boolean', { type: 'boolean' })
.option('number', { type: 'number' })
.option('string', { type: 'string' })
)
.parse(['my-command', 'hello', '--no-boolean', '--number'
The returned array can be parsed again by yargs-parser using the default configuration. If you used custom configuration that you want yargs-unparser to be aware, please fill an issue.
If you coerce in weird ways, things might not work correctly.
$ npm test
$ npm test -- --watch during development
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.
bcoe
bencoe@gmail.com
Estimated unpacked size across 5 packages.
57.8 kB
Includes dependencies.
4 direct · 4 outdated
^5.0.2
6.0.1
^6.0.0
10.0.0
^4.0.0
7.0.0
^2.1.0
4.1.0