
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
hash-to-array
Advanced tools
Turns an arg hash into an array of arguments. Useful when running command line apps with child_process.
Turns an arg hash into an array of arguments. Useful when running command line apps with child_process.
Like minimist in reverse.
Please note that these examples are not good real-world use-cases. There are much better ways of accomplishing what is shown in these examples!
rm -rf dir:
var hashToArray = require('hash-to-array')
var spawn = require('child_process').spawn
var args = hashToArray({
r: true,
f: true,
'/lolz/moar/lol': false
}) //=> [ '-r', '-f', '/lolz/moar/lol' ]
spawn('rm', args)
mkdir -p dir:
var hashToArray = require('hash-to-array')
var spawn = require('child_process').spawn
spawn('mkdir', hashToArray({p: true})) //=> [ '-p' ]
browserify:
var hashToArray = require('hash-to-array')
var spawn = require('child_process').spawn
var args = hashToArray({
'myModule.js': false,
d: true,
outfile: './bundle.js'
}) //=> [ 'myModule.js', '-d', '--outfile', './bundle.js' ]
spawn('browserify', args)
var arr = hashToArray(hash)hash is a map of the input arguments and their corresponding values.
7 -> [7]arr.// Objects are transformed into arrays
hashToArray({ your: 'name' }) // => [ '--your', 'name' ]
hashToArray({ hello: true }) // => [ '--hello' ]
hashToArray({ hello: false }) // => [ 'hello' ]
hashToArray({ 0: 8, 1: false, length: 2 }) // => [ '-0', 8, '1', '--length', 2 ]
// Arrays are unmodified
hashToArray([ '-o', 'two.txt' ]) // => [ '-o', 'two.txt' ]
// Other things are stuffed into arrays
hashToArray('hi there') // => [ 'hi there' ]
hashToArray(17) // => [ 17 ]
hashToArray({
username: 'joseph',
password: 'lolwut',
'debug-level': 12
}) // => [ '--username', 'joseph', '--password', 'lolwut', '--debug-level', 12 ]
Note that boolean values do not get pushed to the array. They signify the presence of prepended dashes. (See examples.)
With npm do:
npm install hash-to-array
FAQs
Turns an arg hash into an array of arguments. Useful when running command line apps with child_process.
The npm package hash-to-array receives a total of 853 weekly downloads. As such, hash-to-array popularity was classified as not popular.
We found that hash-to-array demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.