JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 37182
  • Score
    100M100P100Q144124F
  • License

Simple API for managing options in JavaScript applications.

Package Exports

  • option-cache

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (option-cache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

option-cache NPM version Build Status

Simple API for managing options in JavaScript applications.

Install with npm

npm i option-cache --save

API

Options

Create a new instance of Options.

  • options {Object}: Initialize with default options.
var app = new Options();

.option

Set or get an option.

  • key {String}: The option name.
  • value {*}: The value to set.
  • returns {*}: Returns a value when only key is defined.
app.option('a', true);
app.option('a');
//=> true

.enable

Enable key.

  • key {String}
  • returns {Object} Options: to enable chaining

Example

app.enable('a');

.disable

Disable key.

  • key {String}: The option to disable.
  • returns {Object} Options: to enable chaining

Example

app.disable('a');

.enabled

Check if key is enabled (truthy).

  • key {String}
  • returns: {Boolean}
app.enabled('a');
//=> false

app.enable('a');
app.enabled('a');
//=> true

.disabled

Check if key is disabled (falsey).

  • key {String}
  • returns {Boolean}: Returns true if key is disabled.
app.disabled('a');
//=> true

app.enable('a');
app.disabled('a');
//=> false

.isTrue

Returns true if the value of key is strictly true.

  • key {String}
  • returns {Boolean}: Uses strict equality for comparison.
app.option('a', 'b');
app.isTrue('a');
//=> false

app.option('c', true);
app.isTrue('c');
//=> true

.isFalse

Returns true if the value of key is strictly false.

  • key {String}
  • returns {Boolean}: Uses strict equality for comparison.
app.option('a', null);
app.isFalse('a');
//=> false

app.option('c', false);
app.isFalse('c');
//=> true

.isBoolean

Return true if the value of key is either true or false.

  • key {String}
  • returns {Boolean}: True if true or false.
app.option('a', 'b');
app.isBoolean('a');
//=> false

app.option('c', true);
app.isBoolean('c');
//=> true

.hasOption

Return true if options.hasOwnProperty(key)

  • key {String}
  • returns {Boolean}: True if key is is on options.
app.hasOption('a');
//=> false
app.option('a', 'b');
app.hasOption('a');
//=> true

.flags

Generate an array of command line args from the given keys or all options.

  • keys {Array}
  • returns {Array}: Array of args
// 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']



Example app

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
  }
};

Author

Jon Schlinkert

License

Copyright (c) 2015 Jon Schlinkert
Released under the MIT license


This file was generated by verb-cli on March 19, 2015.