object-to-argv
Convert an object to an array of arguments to pass to a cli process
Note: object-to-argv
is only supported on iojs and node v4+. To use with
an older version of node, please use object-to-argv@1
.
Install
$ npm install object-to-argv
Test
$ npm test
API
objectToArgv(obj:Object, [opts:Object])
If obj
is not an object, it is coerced to one.
opts
can contain the following keys:
equalSign
: will format like['--name=evan']
vs['--name', 'evan']
alwaysSingle
: will always use single dashes like['-name', 'evan']
Example
const convert = const input = name: 'evan' debug: true verbose: false // will be ignored since it is a bool and false test: {} // will be ignored since it is an object test: null // will be ignored since it is null b: true // single letters will only have a single dash n: 'evan'console// => [ '--name', 'evan', '--debug', '-b', '-n', 'evan' ] // or use alwaysSingle optionconst input2 = name: 'evan' debug: true verbose: false // will be ignored since it is a bool and false test: {} // will be ignored since it is an object test: null // will be ignored since it is null b: true // single letters will only have a single dash n: 'evan'console// => [ '-name', 'evan', '-debug', '-b', '-n', 'evan' ] // or use equalSign optionconst input3 = name: 'evan' debug: true verbose: false // will be ignored since it is a bool and false test: {} // will be ignored since it is an object test: null // will be ignored since it is null b: true // single letters will only have a single dash n: 'evan'console// => [ '--name=evan', '--debug', '-b', '-n=evan' ] // or use both options togetherconst input4 = name: 'evan' debug: true verbose: false // will be ignored since it is a bool and false test: {} // will be ignored since it is an object test: null // will be ignored since it is null b: true // single letters will only have a single dash n: 'evan'console// => [ '-name=evan', '-debug', '-b', '-n=evan' ]
Author
Evan Lucas
License
MIT (See LICENSE
for more info)