Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

yargs-unparser

yargs35.2mMIT2.0.0TypeScript support: definitely-typed

Converts back a yargs argv object to its original array form

yargs, unparse, expand, inverse, argv

readme

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

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.0.0 (2020-10-02)

⚠ BREAKING CHANGES

  • upgrade deps drop Node 6/8 (#71)

Code Refactoring

1.6.4 (2020-10-01)

Bug Fixes

  • security: upgraded flat to version ^5.0.2 (9bd7c67)

1.6.3 (2020-06-17)

Bug Fixes

1.6.2 (2020-06-17)

Bug Fixes

  • readme: marketing was injected dubiously into README (#60) (1167667)

1.6.1 (2020-06-17)

Bug Fixes

  • deps: downgrade yargs, such that we continue supporting Node 6 (#57) (f69406c)

1.6.0 (2019-07-30)

Bug Fixes

  • security: update deps addressing recent audit vulnerabilities (#40) (2e74f1b)
  • address bug with camelCased flattened keys (#32) (981533a)
  • deps: updated the lodash version to fix vulnerability (#39) (7375966)
  • package: update yargs to version 10.0.3 (f1eb4cb)
  • package: update yargs to version 11.0.0 (6aa7c91)

Features

  • add interoperation with minimist (ba477f5)

1.5.0 (2018-11-30)

Bug Fixes

  • package: update yargs to version 10.0.3 (f1eb4cb)
  • package: update yargs to version 11.0.0 (6aa7c91)

Features

  • add interoperation with minimist (ba477f5)

1.4.0 (2017-12-30)

Features

  • add interoperation with minimist (ba477f5)