# minimist-options

> Pretty options for minimist

Latest version **4.1.0** (published 2020-05-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install minimist-options
pnpm add minimist-options
yarn add minimist-options
bun add minimist-options
```

## Health

**Score 23/100 (F)** — status: abandoned.

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2020-05-16 |
| First published | 2015-08-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/minimist-options) |
| Module format | CommonJS |
| Node | >= 6 |
| Dependencies | 3 |
| Unpacked size | 8.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 53 |
| Author | Vadim Demedes |
| Maintainers | vdemedes |
| Keywords | minimist, argv, args |

## Links

- npm: https://www.npmjs.com/package/minimist-options
- Repository: https://github.com/vadimdemedes/minimist-options
- Homepage: https://github.com/vadimdemedes/minimist-options#readme
- Issues: https://github.com/vadimdemedes/minimist-options/issues
- npm.io page: https://npm.io/package/minimist-options

## Dependencies (3)

- [arrify](https://npm.io/package/arrify.md) ^1.0.1
- [kind-of](https://npm.io/package/kind-of.md) ^6.0.3
- [is-plain-obj](https://npm.io/package/is-plain-obj.md) ^1.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

- 4.1.0 (latest) — 2020-05-16
- 4.0.2 — 2019-09-29
- 4.0.1 — 2019-03-05
- 4.0.0 — 2019-01-13
- 3.0.2 — 2017-08-09
- 3.0.1 — 2017-05-31
- 3.0.0 — 2017-05-31
- 2.1.0 — 2017-05-31
- 2.0.2 — 2017-02-23
- 2.0.1 — 2016-08-14
- 2.0.0 — 2016-08-13
- 1.0.0 — 2015-08-26

## README

# minimist-options ![test](https://github.com/vadimdemedes/minimist-options/workflows/test/badge.svg) 

> Write options for [minimist](https://npmjs.org/package/minimist) and [yargs](https://npmjs.org/package/yargs) in a comfortable way.
> Supports string, boolean, number and array options.

## Installation

```
$ npm install --save minimist-options
```

## Usage

```js
const buildOptions = require('minimist-options');
const minimist = require('minimist');

const options = buildOptions({
	name: {
		type: 'string',
		alias: 'n',
		default: 'john'
	},

	force: {
		type: 'boolean',
		alias: ['f', 'o'],
		default: false
	},

	score: {
		type: 'number',
		alias: 's',
		default: 0
	},

	arr: {
		type: 'array',
		alias: 'a',
		default: []
	},

	strings: {
		type: 'string-array',
		alias: 's',
		default: ['a', 'b']
	},

	booleans: {
		type: 'boolean-array',
		alias: 'b',
		default: [true, false]
	},

	numbers: {
		type: 'number-array',
		alias: 'n',
		default: [0, 1]
	},

	published: 'boolean',

	// Special option for positional arguments (`_` in minimist)
	arguments: 'string'
});

const args = minimist(process.argv.slice(2), options);
```

instead of:

```js
const minimist = require('minimist');

const options = {
	string: ['name', '_'],
	number: ['score'],
	array: [
		'arr',
		{key: 'strings', string: true},
		{key: 'booleans', boolean: true},
		{key: 'numbers', number: true}
	],
	boolean: ['force', 'published'],
	alias: {
		n: 'name',
		f: 'force',
		s: 'score',
		a: 'arr'
	},
	default: {
		name: 'john',
		f: false,
		score: 0,
		arr: []
	}
};

const args = minimist(process.argv.slice(2), options);
```

## Array options

The `array` types are only supported by [yargs](https://npmjs.org/package/yargs).

[minimist](https://npmjs.org/package/minimist) does _not_ explicitly support array type options. If you set an option multiple times, it will indeed yield an array of values. However, if you only set it once, it will simply give the value as is, without wrapping it in an array. Thus, effectively ignoring `{type: 'array'}`.

`{type: 'array'}` is shorthand for `{type: 'string-array'}`. To have values coerced to `boolean` or `number`, use `boolean-array` or `number-array`, respectively.

## License

MIT © [Vadim Demedes](https://vadimdemedes.com)

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