# object-to-spawn-args

> Converts an object to a child_process.spawn args array

Latest version **2.0.1** (published 2021-03-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install object-to-spawn-args
pnpm add object-to-spawn-args
yarn add object-to-spawn-args
bun add object-to-spawn-args
```

## 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 | 2.0.1 |
| Published | 2021-03-13 |
| First published | 2014-06-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 0 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Lloyd Brookes |
| Maintainers | 75lb |
| Keywords | child_process, spawn |

## Links

- npm: https://www.npmjs.com/package/object-to-spawn-args
- Repository: https://github.com/75lb/object-to-spawn-args
- Homepage: https://github.com/75lb/object-to-spawn-args#readme
- Issues: https://github.com/75lb/object-to-spawn-args/issues
- npm.io page: https://npm.io/package/object-to-spawn-args

## Recent versions

- 2.0.1 (latest) — 2021-03-13
- 2.0.0 — 2019-11-02
- 1.1.1 — 2017-05-12
- 1.1.0 — 2016-02-18
- 1.0.0 — 2015-12-17
- 0.1.2 — 2015-03-17
- 0.1.1 — 2014-06-02
- 0.1.0 — 2014-06-01
- 0.0.0 — 2014-06-01

## README

[![view on npm](https://badgen.net/npm/v/object-to-spawn-args)](https://www.npmjs.org/package/object-to-spawn-args)
[![npm module downloads](https://badgen.net/npm/dt/object-to-spawn-args)](https://www.npmjs.org/package/object-to-spawn-args)
[![Gihub repo dependents](https://badgen.net/github/dependents-repo/75lb/object-to-spawn-args)](https://github.com/75lb/object-to-spawn-args/network/dependents?dependent_type=REPOSITORY)
[![Gihub package dependents](https://badgen.net/github/dependents-pkg/75lb/object-to-spawn-args)](https://github.com/75lb/object-to-spawn-args/network/dependents?dependent_type=PACKAGE)
[![Build Status](https://travis-ci.org/75lb/object-to-spawn-args.svg?branch=master)](https://travis-ci.org/75lb/object-to-spawn-args)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](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
```

* * *

&copy; 2014-21 Lloyd Brookes \<75pound@gmail.com\>.

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