Created
May 26, 2014 21:57
-
-
Save johanbrook/05629c0ce374f18b5125 to your computer and use it in GitHub Desktop.
Turn an object into a argument style array (for use with child_process.spawn, for instance).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('underscore') | |
/** | |
* Takes an key-value hash and returns an array with | |
* the following structure: | |
* | |
* {key: 'val', foo: 'bar'} | |
* => ['--key', 'val', '--foo', 'bar'] | |
*/ | |
var toArgumentArray = function(src) { | |
return _.reduceRight(src, function(prev, val, key) { | |
return prev.concat("--"+key, val) | |
}, []) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment