to-flag

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');
toFlag('abc', true);
toFlag('abc', 'xyz');
toFlag('abc', 'true');
toFlag('abc', 10);
casing
Keys that are camelcase or contain spaces will be dash-cased:
toFlag('fooBar');
toFlag('a b c');
toFlag('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]);
});
Options
invert
When the value is false
an inverted flag is created by default:
toFlag('a', false);
To disable inversion, pass false
on the options:
toFlag('a', false, {invert: false});
Related
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.