Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

minimist-options

4.0.2 • Public • Published

minimist-options Build Status

Write options for minimist in a comfortable way. Support 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: []
    },
 
    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'],
    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);

License

MIT © Vadim Demedes

Install

npm i minimist-options

DownloadsWeekly Downloads

3,459,853

Version

4.0.2

License

MIT

Unpacked Size

6.38 kB

Total Files

5

Last publish

Collaborators

  • avatar