options-to-spawn-args
Converts an options object to an array suitable for passing to child_process.spawn()
.
- Single letter object properties (e.g.
c: "red"
) convert to short-option args (e.g.-c red
). - Longer object properties (e.g.
colour: "red"
) convert to long-option args (e.g.--colour red
). - Object property values equalling
true
convert to flags (e.g.-l
). - Object property values containing white spaces get auto quoted (e.g.
c: "hello world"
) convert to (e.g.-c "hello world"
).
This options object:
const options = o: true t: "hello" three: "world" four: true
converts to
"-o" "-t" "hello" "--three" "world" "--four"
Installation
$ npm install options-to-spawn-args --save
Usage
;; const options = l: true a: true; ;
Options
[string|function]=standard
prefix Example
const options = resize: '50%' r: '100%' // [ '-resize', '50%', '-r', '100%' ] // [ '++resize', '50%', '--r', '100%' ]
[boolean]=false
equal Example
const options = resize: '50%' // [ '--resize=50%' ]
[boolean]=false
quote Example
const options = resize: '50%' demo: 10 // [ '--resize', '"50%"', '--demo', '"10"' ]