JSPM

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

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

options-cache NPM version

Get and set options easily, for node.js projects.

Install

Install with npm:

npm i options-cache --save-dev

API

Options

Initialize a new Options cache.

  • options {Object}: Initialize with default options.

Example:

In your application:

var util = require('util');
var Options = require('options-cache');

function App(options) {
  Options.call(this, options);
}
util.inherits(App, Options);

App.prototype.foo = function(value) {
  this.enable(value);
};

App.prototype.bar = function(value) {
  if (this.enabled(value)) {
    // do something
  }
};

.option

Set or get an option.

  • key {String}
  • value {*}
  • returns {Object} Options: to enable chaining
app.option('a', true)
app.option('a')
// => true

.set

Assign value to key or return the value of key.

  • key {String}
  • value {*}: The value to set.
  • returns {Object} Options: to enable chaining
app.set('foo', true)

.get

Return the stored value of key.

  • key {String}
app.set('foo', true)
app.get('foo')
//=> true

.extend

Extend the options with the given object. This method is chainable.

  • returns {Options}: for chaining

Example

options
  .extend({foo: 'bar'}, {baz: 'quux'});
  .extend({fez: 'bang'});

Or define the property to extend:

options
  .extend('a', {foo: 'bar'}, {baz: 'quux'})
  .extend('b', {fez: 'bang'})
  .extend('a.b.c', {fez: 'bang'});

.enabled

Check if key is enabled (truthy).

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

app.enable('foo')
app.enabled('foo')
// => true

.disabled

Check if key is disabled (falsey).

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

app.enable('foo')
app.disabled('foo')
// => false

.enable

Enable key.

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

Example

app.enable('foo')

.disable

Disable key.

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

Example

app.disable('foo')

.clear

Remove key from the options, or if no value is specified the entire options is reset.

Example:

options.clear();

Author

Jon Schlinkert

License

Copyright (c) 2014 Jon Schlinkert, contributors.
Released under the MIT license


This file was generated by verb-cli on August 29, 2014.