Skip to content

Instantly share code, notes, and snippets.

@johanbrook
Created May 26, 2014 21:57
Show Gist options
  • Save johanbrook/05629c0ce374f18b5125 to your computer and use it in GitHub Desktop.
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).
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