You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

object-to-argv

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-to-argv

Convert an object to an array of arguments to pass to a cli process

2.0.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

object-to-argv

Build Status Coverage Status

Convert an object to an array of arguments to pass to a cli process

Note: object-to-argv is only supported on iojs and node v4+. To use with an older version of node, please use object-to-argv@1.

Install

$ npm install object-to-argv

Test

$ npm test

API

objectToArgv(obj:Object, [opts:Object])

If obj is not an object, it is coerced to one.

opts can contain the following keys:

  • equalSign: will format like ['--name=evan'] vs ['--name', 'evan']
  • alwaysSingle: will always use single dashes like ['-name', 'evan']

Example

const convert = require('object-to-argv')
const input = {
  name: 'evan'
, debug: true
, verbose: false // will be ignored since it is a bool and false
, test: {}       // will be ignored since it is an object
, test: null     // will be ignored since it is null
, b: true        // single letters will only have a single dash
, n: 'evan'
}
console.log(convert(input))
// => [ '--name', 'evan', '--debug', '-b', '-n', 'evan' ]

// or use alwaysSingle option
const input2 = {
  name: 'evan'
, debug: true
, verbose: false // will be ignored since it is a bool and false
, test: {}       // will be ignored since it is an object
, test: null     // will be ignored since it is null
, b: true        // single letters will only have a single dash
, n: 'evan'
}
console.log(convert(input2, {
  alwaysSingle: true
}))
// => [ '-name', 'evan', '-debug', '-b', '-n', 'evan' ]

// or use equalSign option
const input3 = {
  name: 'evan'
, debug: true
, verbose: false // will be ignored since it is a bool and false
, test: {}       // will be ignored since it is an object
, test: null     // will be ignored since it is null
, b: true        // single letters will only have a single dash
, n: 'evan'
}
console.log(convert(input3, {
  equalSign: true
}))
// => [ '--name=evan', '--debug', '-b', '-n=evan' ]

// or use both options together
const input4 = {
  name: 'evan'
, debug: true
, verbose: false // will be ignored since it is a bool and false
, test: {}       // will be ignored since it is an object
, test: null     // will be ignored since it is null
, b: true        // single letters will only have a single dash
, n: 'evan'
}
console.log(convert(input4, {
  alwaysSingle: true
, equalSign: true
}))
// => [ '-name=evan', '-debug', '-b', '-n=evan' ]

Author

Evan Lucas

License

MIT (See LICENSE for more info)

FAQs

Package last updated on 05 Nov 2015

Did you know?

Socket

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.

Install

Related posts