🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

to-flag

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

to-flag

Create a command-line argument from a string or string (key) and value.

1.0.0
latest
Source
npm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

to-flag NPM version Build Status

Create a command-line argument from a string or string (key) and value.

Install

Install with npm

$ npm i to-flag --save

Usage

var toFlag = require('to-flag');

toFlag('abc');
//=> '--abc'

toFlag('abc', true);
//=> '--abc'

toFlag('abc', 'xyz');
//=> '--abc=xyz'

toFlag('abc', 'true');
//=> '--abc=true'

toFlag('abc', 10);
//=> '--abc=10'

casing

Keys that are camelcase or contain spaces will be dash-cased:

toFlag('fooBar');
//=> '--foo-bar'

toFlag('a b c');
//=> '--a-b-c'

toFlag('A');
//=> '--a'

Usage example

var obj = {
  foo: 'bar',
  abc: true,
  xyz: 10,
  one: false
};

var args = Object.keys(obj).map(function (key) {
  return toFlag(key, obj[key]);
});
//=> ['--foo=bar', '--abc', '--xyz=10', '--no-one']

Options

invert

When the value is false an inverted flag is created by default:

toFlag('a', false);
//=> '--no-a'

To disable inversion, pass false on the options:

toFlag('a', false, {invert: false});
//=> '--a'
  • minimist-plugins: Simple wrapper to make minimist pluggable. ~20 sloc.
  • minimist-events: Add events to minimist, ~30 sloc.
  • minimist-methods: Map your node.js application's methods to command line arguments.
  • minimist-expand: Expand minimist args with expand-object.
  • to-flags: Convert the properties of an object to command line flags.

Run tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

This was originally inspired by grunt.option.

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.

This file was generated by verb-cli on August 07, 2015.

Keywords

arg

FAQs

Package last updated on 07 Aug 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