Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

option-cache

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

option-cache

Simple API for managing options in JavaScript applications.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32K
increased by15.02%
Maintainers
1
Weekly downloads
 
Created
Source

option-cache NPM version

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 options = 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

.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

.isBoolean

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

  • keys {Array}
  • returns: {Array}

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




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 on February 13, 2015.

Keywords

FAQs

Package last updated on 13 Feb 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc