# hash-to-array

> Turns an arg hash into an array of arguments. Useful when running command line apps with child_process.

Latest version **1.0.2** (published 2020-06-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install hash-to-array
pnpm add hash-to-array
yarn add hash-to-array
bun add hash-to-array
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-06-15 |
| First published | 2014-12-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Joseph Dykstra |
| Maintainers | artskydj |
| Keywords | hash, argv, stringify |

## Links

- npm: https://www.npmjs.com/package/hash-to-array
- Repository: https://github.com/ArtskydJ/hash-to-array
- Issues: https://github.com/ArtskydJ/hash-to-array/issues
- npm.io page: https://npm.io/package/hash-to-array

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2020-06-15
- 1.0.1 — 2015-06-23
- 1.0.0 — 2014-12-31
- 0.0.2 — 2014-12-23
- 0.0.1 — 2014-12-22

## README

# hash-to-array

[![Build Status](https://travis-ci.org/ArtskydJ/hash-to-array.svg)](https://travis-ci.org/ArtskydJ/hash-to-array)

Turns an arg hash into an array of arguments. Useful when running command line apps with child_process.

Like [minimist](https://github.com/substack/minimist) in reverse.

# examples

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:
```node
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:
```node
var hashToArray = require('hash-to-array')
var spawn = require('child_process').spawn

spawn('mkdir', hashToArray({p: true})) //=> [ '-p' ]
```

browserify:
```node
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)
```

# usage

## `var arr = hashToArray(hash)`

- `hash` is a map of the input arguments and their corresponding values.
	- If it is already an array, it returns it.
	- If it is not an object, it stuffs it into an array. E.g. `7` -> `[7]`
- **Returns** `arr`.

<!-- js
var hashToArray = require('./')
-->

```js
// 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.)

# install

With [npm](https://nodejs.org/download) do:

	npm install hash-to-array

# license

[MIT](https://choosealicense.com/licenses/mit/)

---
_Source: https://npm.io/package/hash-to-array · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
