JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 265758
  • Score
    100M100P100Q186005F
  • License MIT

Converts an object to a child_process.spawn args array

Package Exports

  • object-to-spawn-args

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (object-to-spawn-args) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

view on npm npm module downloads Gihub repo dependents Gihub package dependents Build Status js-standard-style

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:

> 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.

> 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.

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

$ npm install object-to-spawn-args

© 2014-21 Lloyd Brookes <75pound@gmail.com>.