https://github.com/75lb/object-to-spawn-args
Converts an options object to an array suitable for passing to child_process.spawn()
https://github.com/75lb/object-to-spawn-args
child-process javascript-library nodejs spawn
Last synced: 9 months ago
JSON representation
Converts an options object to an array suitable for passing to child_process.spawn()
- Host: GitHub
- URL: https://github.com/75lb/object-to-spawn-args
- Owner: 75lb
- License: mit
- Created: 2014-06-01T13:37:30.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2021-03-13T21:20:51.000Z (about 5 years ago)
- Last Synced: 2025-06-04T14:18:59.210Z (10 months ago)
- Topics: child-process, javascript-library, nodejs, spawn
- Language: JavaScript
- Homepage:
- Size: 29.3 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.org/package/object-to-spawn-args)
[](https://www.npmjs.org/package/object-to-spawn-args)
[](https://github.com/75lb/object-to-spawn-args/network/dependents?dependent_type=REPOSITORY)
[](https://github.com/75lb/object-to-spawn-args/network/dependents?dependent_type=PACKAGE)
[](https://travis-ci.org/75lb/object-to-spawn-args)
[](https://github.com/feross/standard)
# object-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`).
## Synopsis
Simple usage:
```js
> const objectToSpawnArgs = require('object-to-spawn-args')
> const spawnArgs = objectToSpawnArgs({
l: true,
c: 'red',
name: 'pete',
tramp: true
})
> console.log(spawnArgs)
[ '-l', '-c', 'red', '--name', 'pete', '--tramp' ]
```
Alternatively, convert to `--object=value` notation.
```js
> const options = {
l: true,
c: 'red',
name: 'pete',
tramp: true
}
> const spawnArgs = objectToSpawnArgs(options, { optionEqualsValue: true })
> console.log(spawnArgs)
[ '-l', '-c=red', '--name=pete', '--tramp' ]
```
Typical real-life example.
```js
const objectToSpawnArgs = require('object-to-spawn-args')
const spawn = require('child_process').spawn
const options = {
l: true,
a: true
}
spawn('ls', objectToSpawnArgs(options), { stdio: 'inherit' })
```
## Installation
```sh
$ npm install object-to-spawn-args
```
* * *
© 2014-21 Lloyd Brookes \<75pound@gmail.com\>.