Socket
Socket
Sign inDemoInstall

object-to-argv

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

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


Version published
Weekly downloads
131
decreased by-61.13%
Maintainers
1
Install size
6.81 kB
Created
Weekly downloads
 

Readme

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

Last updated on 05 Nov 2015

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc