yargs-unparser

WebJar for yargs-unparser

License

License

MIT
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

yargs-unparser
Last Version

Last Version

2.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

yargs-unparser
WebJar for yargs-unparser
Project URL

Project URL

https://www.webjars.org
Source Code Management

Source Code Management

https://github.com/yargs/yargs-unparser

Download yargs-unparser

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/yargs-unparser/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>yargs-unparser</artifactId>
    <version>2.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/yargs-unparser/
implementation 'org.webjars.npm:yargs-unparser:2.0.0'
// https://jarcasting.com/artifacts/org.webjars.npm/yargs-unparser/
implementation ("org.webjars.npm:yargs-unparser:2.0.0")
'org.webjars.npm:yargs-unparser:jar:2.0.0'
<dependency org="org.webjars.npm" name="yargs-unparser" rev="2.0.0">
  <artifact name="yargs-unparser" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='yargs-unparser', version='2.0.0')
)
libraryDependencies += "org.webjars.npm" % "yargs-unparser" % "2.0.0"
[org.webjars.npm/yargs-unparser "2.0.0"]

Dependencies

compile (4)

Group / Artifact Type Version
org.webjars.npm : camelcase jar [6.0.0,7)
org.webjars.npm : decamelize jar [4.0.0,5)
org.webjars.npm : flat jar [5.0.2,6)
org.webjars.npm : is-plain-obj jar [2.1.0,3)

Project Modules

There are no modules declared in this project.

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

org.webjars.npm

Versions

Version
2.0.0
1.6.0
1.5.0