Stringify an object to command line options
npm install --save opted
Opted is not a command line option parser. Rather, it is a library for stringifying an object into a list of command line arguments. E.g.
var opted = require('opted');
var args = opted({ foo: 'bar' });
console.log(args); // ['--foo', 'bar']
Options are kebab-cased and prefixed with '--'.
console.log( opted({ foo: 'bar' }) ); // ['--foo', 'bar']
console.log( opted({ fooBar: 'baz' }) ); // ['--foo-bar', 'baz']
Options that have single letter abbreviations can also be used.
console.log( opted({ f: 'bar' }) ); // ['-f', 'bar']
Options that are simple "on", but have no value, can be set to true
. Setting a flag to false, will add 'no' to the beginning.
console.log( opted({ bananas: true }) ); // ['--bananas']
console.log( opted({ bananas: false }) ); // ['--no-bananas']
Options that include an equal sign will keep the equal sign.
console.log( opted({ 'name=', 'Andrew' }) ); // ['--name=Andrew']
Multiple options for a single flag can be passed in an array.
console.log( opted({ member: ['Bob', 'Larry'] }) ); // ['--member', 'Bob', '--member', 'Larry']
No problem. Just enable crazy-arg mode by passing true as the second parameter.
console.log( opted({ hello: 'world' }, true) ); // ['-hello', 'world']
Please see the contribution guidelines.