Socket
Book a DemoInstallSign in
Socket

options-cache

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

options-cache

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

Source
npmnpm
Version
0.2.1
Version published
Weekly downloads
14
55.56%
Maintainers
1
Weekly downloads
 
Created
Source

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 {Cache}: 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 cache, 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 09, 2014.

Keywords

node.js

FAQs

Package last updated on 14 Aug 2014

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