Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
option-cache
Advanced tools
Simple API for managing options in JavaScript applications.
Install with npm
$ npm i option-cache --save
(Table of contents generated by verb)
Create a new instance of Options
.
Params
options
{Object}: Initialize with default options.Example
var app = new Options();
Set or get an option.
Params
key
{String}: The option name.value
{*}: The value to set.returns
{*}: Returns a value
when only key
is defined.Example
app.option('a', true);
app.option('a');
//=> true
Enable key
.
Params
key
{String}returns
{Object} Options
: to enable chainingExample
app.enable('a');
Disable key
.
Params
key
{String}: The option to disable.returns
{Object} Options
: to enable chainingExample
app.disable('a');
Check if key
is enabled (truthy).
Params
key
{String}returns
{Boolean}Example
app.enabled('a');
//=> false
app.enable('a');
app.enabled('a');
//=> true
Check if key
is disabled (falsey).
Params
key
{String}returns
{Boolean}: Returns true if key
is disabled.Example
app.disabled('a');
//=> true
app.enable('a');
app.disabled('a');
//=> false
Returns true if the value of key
is strictly true
.
Params
key
{String}returns
{Boolean}: Uses strict equality for comparison.Example
app.option('a', 'b');
app.isTrue('a');
//=> false
app.option('c', true);
app.isTrue('c');
//=> true
Returns true if the value of key
is strictly false
.
Params
key
{String}returns
{Boolean}: Uses strict equality for comparison.Example
app.option('a', null);
app.isFalse('a');
//=> false
app.option('c', false);
app.isFalse('c');
//=> true
Return true if the value of key is either true
or false
.
Params
key
{String}returns
{Boolean}: True if true
or false
.Example
app.option('a', 'b');
app.isBoolean('a');
//=> false
app.option('c', true);
app.isBoolean('c');
//=> true
Return true if options.hasOwnProperty(key)
Params
key
{String}returns
{Boolean}: True if key
is is on options.Example
app.hasOption('a');
//=> false
app.option('a', 'b');
app.hasOption('a');
//=> true
Generate an array of command line args from the given keys
or all options.
Params
keys
{Array}returns
{Array}: Array of argsExample
// set some options
app.option('foo', 'bar');
app.option('abc', true);
app.option('xyz', 10);
app.option('one', false);
// create command line args for all options
app.flags();
//=> ['--foo=bar', '--abc', '--xyz=10', '--no-one']
// or specific options
app.flags(['foo', 'abc']);
//=> ['--foo=bar', '--abc']
Use options-cache in your javascript application:
var util = require('util');
var Options = require('options-cache');
function App(options) {
Options.call(this, options);
this.init();
}
util.inherits(App, Options);
App.prototype.init = function() {
this.option('cwd', process.cwd());
this.option('foo', 'bar');
};
App.prototype.a = function(value) {
this.enable(value);
};
App.prototype.b = function(value) {
if (this.enabled(value)) {
// do something
} else {
// do something else
}
};
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Install dev dependencies:
$ npm i -d && npm test
Jon Schlinkert
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb-cli on June 13, 2015.
FAQs
Simple API for managing options in JavaScript applications.
The npm package option-cache receives a total of 22,880 weekly downloads. As such, option-cache popularity was classified as popular.
We found that option-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.