Big update!Introducing GitHub Bot Commands. Learn more
Socket
Log inBook a demo

minimist-options

Package Overview
Dependencies
3
Maintainers
1
Versions
12
Issues
File Explorer

Advanced tools

minimist-options

Pretty options for minimist

    4.1.0latest

Version published
Maintainers
1
Weekly downloads
8,853,151
decreased by-10.35%

Weekly downloads

Changelog

Source

Highlights

  • Support boolean and number arrays (#19) 0df435f

Thanks

Thanks to @ulken for implementing support for string, boolean and number arrays when using this module with yargs!

https://github.com/vadimdemedes/minimist-options/compare/v4.0.2...v4.1.0

Readme

Source

minimist-options test

Write options for minimist and yargs in a comfortable way. Supports string, boolean, number and array options.

Installation

$ npm install --save minimist-options

Usage

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:

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.

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

Keywords

FAQs

What is minimist-options?

Pretty options for minimist

Is minimist-options popular?

The npm package minimist-options receives a total of 8,466,662 weekly downloads. As such, minimist-options popularity was classified as popular.

Is minimist-options well maintained?

We found that minimist-options demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 1 open source maintainer collaborating on the project.

Last updated on 16 May 2020

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket

Product

Subscribe to our newsletter

Get open source security insights delivered straight into your inbox. Be the first to learn about new features and product updates.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc