# yargs-unparser

> Converts back a yargs argv object to its original array form

Latest version **2.0.0** (published 2020-10-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install yargs-unparser
pnpm add yargs-unparser
yarn add yargs-unparser
bun add yargs-unparser
```

## Health

**Score 38/100 (D)** — status: abandoned.

Positive: has types package; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-10-02 |
| First published | 2017-08-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/yargs-unparser) |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 4 |
| Unpacked size | 13.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Author | André Cruz |
| Maintainers | satazor, bcoe, oss-bot |
| Keywords | yargs, unparse, expand, inverse, argv |

## Links

- npm: https://www.npmjs.com/package/yargs-unparser
- Repository: https://github.com/yargs/yargs-unparser
- Issues: https://github.com/yargs/yargs-unparser/issues
- npm.io page: https://npm.io/package/yargs-unparser

## Dependencies (4)

- [flat](https://npm.io/package/flat.md) ^5.0.2
- [camelcase](https://npm.io/package/camelcase.md) ^6.0.0
- [decamelize](https://npm.io/package/decamelize.md) ^4.0.0
- [is-plain-obj](https://npm.io/package/is-plain-obj.md) ^2.1.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2020-10-02
- 1.6.0 (next) — 2019-07-30
- 1.6.4 — 2020-10-01
- 1.6.3 — 2020-06-17
- 1.6.1 — 2020-06-17
- 1.5.1 — 2019-07-30
- 1.5.0 — 2018-12-05
- 1.4.0 — 2017-12-30
- 1.3.0 — 2017-11-05
- 1.2.0 — 2017-10-23
- 1.1.0 — 2017-10-09
- 1.0.3 — 2017-08-29
- 1.0.2 — 2017-08-14
- 1.0.1 — 2017-08-14
- 1.0.0 — 2017-08-14

## README

# yargs-unparser

[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url]

[npm-url]:https://npmjs.org/package/yargs-unparser
[npm-image]:http://img.shields.io/npm/v/yargs-unparser.svg
[downloads-image]:http://img.shields.io/npm/dm/yargs-unparser.svg

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](https://github.com/yargs/yargs-parser).

The code originally lived in [MOXY](https://github.com/moxystudio)'s GitHub but was later moved here for discoverability.


## Installation

`$ npm install yargs-unparser`


## Usage

```js
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](https://github.com/yargs/yargs-parser#requireyargs-parserargs-opts) so that duplicate options aren't generated
- `default`: The [default](https://github.com/yargs/yargs-parser#requireyargs-parserargs-opts) values so that the options with default values are omitted
- `command`: The [command](https://github.com/yargs/yargs/blob/master/docs/advanced.md#commands) first argument so that command names and positional arguments are handled correctly

### Example with `command` options

```js
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](https://github.com/yargs/yargs-unparser/issues).

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](https://nodejs.org/en/about/releases/). Here's [a
post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).

## License

[MIT License](http://opensource.org/licenses/MIT)

---
_Source: https://npm.io/package/yargs-unparser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
