2.0.0 • Published 5 years ago

yargs-unparser v2.0.0

Weekly downloads
3,319,816
License
MIT
Repository
github
Last release
5 years ago

yargs-unparser

NPM version Downloads

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 = 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 generated
  • default: The default values so that the options with default values are omitted
  • command: The command first argument so that command names and positional arguments are handled correctly

Example with command options

const 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', '4', '--string', 'foo']);
// { positional: 'hello', boolean: false, number: 4, string: 'foo', _: ['my-command'] }

const unparsedArgv = unparse(argv, {
    command: 'my-command <positional>',
});
// ['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.

License

MIT License

mochaws-scripts@sonammalhotra/lotide@smishra17/lotide@cheapthrills/lotide@iobroker-community-adapters/iobroker.device-watcher@newhorizon-tech/dd-npm-package-templatelevibestliblevibestlib2levilibtest19levilibtest24levilibtest25levilibtest26levilibtest27levilibtest28levilibtest29levinodelib@nicholasjj/lotide@wumijs/clicclibyarntest@everything-registry/sub-chunk-3199winx-form-winxwebdatabasetest1webdatabasetest10wskongkoinsparse-settestweblibapitest-solidity-npmtestlib17swan-toolkitthe_helper_packagethe_helper_packagesvitaqai-mocha@donkswap/community-token-list@donkswap/default-token-list@donnadonnana1/lotide@coconuttt/lotide@ct-note/embed@cynax/cli-app-maker@darkobits/nr@cptntz2119/lotide@dowdev/lotide@borealisswap/borealis-swap-lib@benfinlay/lotide@rstock.co/lotide@pearl-d/lotidejuicyvojosh-fcak0mmand3r@lsby/log_manage@kangarooswapfinance/v2-corestock-ticker-react-widgettype-your-package-name-hereu-scripts-utilsui4htmlterminalmanagertldrawlignintip4@aidanantony/lotide@amandip.h/lotide@arian324/lotide@artossystems/solutions-scripts@amoham/lotide-library@aurelianoa/metadataupdatable@avinashbharti97/detox@astrangegoatintheshadows/lotide@astridcha1x/lotide@afria/afria-libraries@aiman03at/lotide@b1u3too/lotide@bebopskull/lotide@beckpar/lotide@amblade/patswap-default-token-list@bethanypaul989/lotide@bseibz/lotide@c_dzivkovic/hello-world-package@brendsmvreal/lotide@checkup/cli@checkup/core@chiaraani/bouncing-ball@chakra-swap/core3qberlin@abdmmn/lotide@aalibarre/lotide@chazdean/lotide@bossswap/default-token-list@bonsaiswap-lib/lib@bonsaiswapv3/core@bonsaiswapv3/deploy@bowogfc/bbpolymer@dexthefish/lotide@danispin/lotide@credbayswap/default-token-list@dannyjiang111/lotide2yarn-audit-fix-ngyarn-toolyakumo-mochayakumo-yargsyakumoyakumo-core-patch
2.0.0

5 years ago

1.6.4

5 years ago

1.6.3

5 years ago

1.6.1

5 years ago

1.6.0

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago