Socket
Socket
Sign inDemoInstall

opted

Package Overview
Dependencies
1
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    opted

Stringify an object to command line options


Version published
Weekly downloads
14K
decreased by-13.05%
Maintainers
1
Install size
1.36 MB
Created
Weekly downloads
 

Readme

Source

Build Status downloads npm Code Climate Test Coverage dependencies

opted

Stringify an object to command line options

Installation

npm install --save opted

Usage

Opted is not a command line option parser. Rather, it is a library for stringifying an object into a list of command line arguments. E.g.

var opted = require('opted');
var args = opted({ foo: 'bar' });
console.log(args); // ['--foo', 'bar']

Types of flags

Long

Options are kebab-cased and prefixed with '--'.

console.log( opted({ foo: 'bar' }) ); // ['--foo', 'bar']
console.log( opted({ fooBar: 'baz' }) ); // ['--foo-bar', 'baz']

Short

Options that have single letter abbreviations can also be used.

console.log( opted({ f: 'bar' }) ); // ['-f', 'bar']

Boolean

Options that are simple "on", but have no value, can be set to true. Setting a flag to false, will add 'no' to the beginning.

console.log( opted({ bananas: true }) ); // ['--bananas']
console.log( opted({ bananas: false }) ); // ['--no-bananas']

Equal style

Options that include an equal sign will keep the equal sign.

console.log( opted({ 'name=', 'Andrew' }) ); // ['--name=Andrew']

List

Multiple options for a single flag can be passed in an array.

console.log( opted({ member: ['Bob', 'Larry'] }) ); // ['--member', 'Bob', '--member', 'Larry']

But wait, the tool I need to pass args to is some bizarre abomination like "find" that uses single dashes...

No problem. Just enable crazy-arg mode by passing true as the second parameter.

console.log( opted({ hello: 'world' }, true) ); // ['-hello', 'world']

Contributing

Please see the contribution guidelines.

Keywords

FAQs

Last updated on 11 Mar 2017

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