yargs-unparser
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.
Installation
$ npm install yargs-unparser
Usage
const parse = ;const unparse = ; const argv = ;// { boolean: false, number: 4, string: 'foo', _: [] } const unparsedArgv = ;// ['--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 correctly
command
options
Example with const yargs = ;const unparse = ; const argv = yargs ;// { positional: 'hello', boolean: false, number: 4, string: 'foo', _: ['my-command'] } const unparsedArgv = ;// ['my-command', 'hello', '--no-boolean', '--number', '4', '--string', 'foo'];
Caveats
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.
Tests
$ npm test
$ npm test -- --watch
during development
Supported Node.js Versions
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.