$ gnpm install tiny-parse-argv
A tiny function for parsing process.argv, a modern rewrite of a sensible subset of minimist.
The following features are provided:
-f, -f some, -f 123, -f123, -abc, -abc 123, -abc123, -f some -f other.--foo, --foo some, --foo 123, --foo=123, --foo=some, --foo some --foo other.false by default: --no-foo, --no-bar.-f one two three, --foo one two three../app.sh with some list of arguments.options.boolean: the value for the listed flags will always be coerced to a boolean.options.string: the value for the listed flags will always be coerced to a string.options.eager: the listed flags are considered to be eager, and will consume multiple consecutive non-flag values.options.variadic: the listed flags are considered to be variadic, and their value, if present, will always be an array.options.required: the listed flags are considered to be required, if some are missing options.onMissing will be called.options.alias: if any aliased flag is assigned then all the aliases for it will be assigned too, automatically.options.default: an object containing default values, which will be used if not overridded by the argv array.options.onInvalid: a function that will be called if any of the provided flags have an invalid value, e.g. a boolean value for a string flag.options.onMissing: a function that will be called if any of the required flags is missing. If a default value is provided for a flag it won't be considered as missing.options.onUnknown: a function that will be called if any of the flags are unknown, i.e. not listed as either a boolean, a string, or an alias. If a default value is provided for a flag it won't be considered as unknown.--: a special flag that stops parsing, everything after it will be copied, untouched, into the -- property of the return object.minimistThe following differences exist compared to minimist:
option['--'] set to false is not supported, it's as if it's always set to true.option.boolean set to true is not supported, you should always explicitly list all your supported boolean flags instead.option.boolean set to a single string is not supported, always provide an array of flags instead.option.string set to a single string is not supported, always provide an array of flags instead.option.alias mapping to a single string is not supported, always provide an array of aliases instead.option.stopEarly is not supported, it's as if it's always set to false.path-prop's unflat function for that.Other than that it should work pretty much identically, since we are basically using the same tests.
npm install --save tiny-parse-argv
import parseArgv from 'tiny-parse-argv';
parseArgv ([ '-f', '--foo', 'some', 'argument', '--', '--app-flag' ]);
// => { f: true, foo: 'some', _: ['argument'], '--': ['--app-flag'] }
MIT © Fabio Spampinato
Copyright 2013 - present © cnpmjs.org | Home |