option-cache
Advanced tools
Comparing version 3.2.0 to 3.3.2
37
index.js
@@ -28,3 +28,6 @@ /*! | ||
} | ||
this.options = options || {}; | ||
this.options = this.options || {}; | ||
if (options) { | ||
this.option(options); | ||
} | ||
} | ||
@@ -75,12 +78,36 @@ | ||
if (type !== 'object' && type !== 'array') { | ||
var msg = 'expected option to be ' | ||
+ 'a string, object or array'; | ||
var msg = 'expected option to be a string, object or array'; | ||
throw new TypeError(msg); | ||
} | ||
return this.mergeOptions.apply(this, arguments); | ||
}, | ||
/** | ||
* Merge an object, list of objects, or array of objects, | ||
* onto the `app.options`. | ||
* | ||
* @param {Object} `options` | ||
* @return {Object} | ||
* @api public | ||
*/ | ||
mergeOptions: function(options) { | ||
var args = [].slice.call(arguments); | ||
if (type === 'array') { | ||
if (Array.isArray(options)) { | ||
args = utils.flatten(args); | ||
} | ||
this.visit('option', args); | ||
var len = args.length; | ||
var idx = -1; | ||
while (++idx < len) { | ||
var arg = args[idx]; | ||
for (var key in arg) { | ||
if (arg.hasOwnProperty(key)) { | ||
var val = arg[key]; | ||
this.emit('option', key, val); | ||
utils.set(this.options, key, val); | ||
} | ||
} | ||
} | ||
return this; | ||
@@ -87,0 +114,0 @@ }, |
{ | ||
"name": "option-cache", | ||
"description": "Simple API for managing options in JavaScript applications.", | ||
"version": "3.2.0", | ||
"version": "3.3.2", | ||
"homepage": "https://github.com/jonschlinkert/option-cache", | ||
@@ -14,3 +14,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"index.js", | ||
"utils.js" | ||
"lib/" | ||
], | ||
@@ -22,3 +22,4 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "mocha", | ||
"docs": "verb" | ||
}, | ||
@@ -29,8 +30,8 @@ "dependencies": { | ||
"component-emitter": "^1.2.0", | ||
"get-value": "^2.0.0", | ||
"get-value": "^2.0.3", | ||
"has-value": "^0.3.0", | ||
"kind-of": "^3.0.2", | ||
"lazy-cache": "^0.2.4", | ||
"set-value": "^0.3.1", | ||
"to-object-path": "^0.2.0" | ||
"lazy-cache": "^1.0.3", | ||
"set-value": "^0.3.3", | ||
"to-object-path": "^0.3.0" | ||
}, | ||
@@ -40,2 +41,3 @@ "devDependencies": { | ||
"gulp-eslint": "^1.1.1", | ||
"gulp-format-md": "^0.1.7", | ||
"gulp-istanbul": "^0.10.1", | ||
@@ -64,11 +66,26 @@ "gulp-mocha": "^2.1.3", | ||
"verb": { | ||
"run": true, | ||
"toc": false, | ||
"layout": { | ||
"name": "default", | ||
"sections": [ | ||
{ | ||
"heading": "author", | ||
"placement": "before", | ||
"contents": "{%= doc('CHANGELOG.md') %}" | ||
} | ||
] | ||
}, | ||
"tasks": [ | ||
"readme" | ||
], | ||
"plugins": [ | ||
"gulp-format-md" | ||
], | ||
"related": { | ||
"list": [ | ||
"base", | ||
"map-cache", | ||
"cache-base", | ||
"config-cache", | ||
"engine-cache", | ||
"loader-cache", | ||
"parser-cache", | ||
"helper-cache" | ||
"config-cache" | ||
] | ||
@@ -75,0 +92,0 @@ }, |
160
README.md
@@ -1,2 +0,2 @@ | ||
# option-cache [![NPM version](https://badge.fury.io/js/option-cache.svg)](http://badge.fury.io/js/option-cache) [![Build Status](https://travis-ci.org/jonschlinkert/option-cache.svg)](https://travis-ci.org/jonschlinkert/option-cache) | ||
# option-cache [![NPM version](https://img.shields.io/npm/v/option-cache.svg)](https://www.npmjs.com/package/option-cache) [![Build Status](https://img.shields.io/travis/jonschlinkert/option-cache.svg)](https://travis-ci.org/jonschlinkert/option-cache) | ||
@@ -7,3 +7,3 @@ > Simple API for managing options in JavaScript applications. | ||
Install with [npm](https://www.npmjs.com/) | ||
Install with [npm](https://www.npmjs.com/): | ||
@@ -14,14 +14,35 @@ ```sh | ||
## Docs | ||
## Example app | ||
- [API](#api) | ||
- [Example app](#example-app) | ||
- [Related](#related) | ||
- [Contributing](#contributing) | ||
- [Running tests](#running-tests) | ||
- [Coverage](#coverage) | ||
- [Changelog](#changelog) | ||
- [Author](#author) | ||
- [License](#license) | ||
Use options-cache in your javascript application: | ||
```js | ||
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 | ||
} | ||
}; | ||
``` | ||
## API | ||
@@ -43,3 +64,3 @@ | ||
### [.option](index.js#L53) | ||
### [.option](index.js#L56) | ||
@@ -62,4 +83,12 @@ Set or get an option. | ||
### [.hasOption](index.js#L103) | ||
Merge an object, list of objects, or array of objects, | ||
onto the `app.options`. | ||
**Params** | ||
* `options` **{Object}** | ||
* `returns` **{Object}** | ||
### [.hasOption](index.js#L130) | ||
Return true if `options.hasOwnProperty(key)` | ||
@@ -82,3 +111,3 @@ | ||
### [.enable](index.js#L122) | ||
### [.enable](index.js#L149) | ||
@@ -98,3 +127,3 @@ Enable `key`. | ||
### [.disable](index.js#L139) | ||
### [.disable](index.js#L166) | ||
@@ -114,3 +143,3 @@ Disable `key`. | ||
### [.enabled](index.js#L161) | ||
### [.enabled](index.js#L188) | ||
@@ -135,3 +164,3 @@ Check if `prop` is enabled (truthy). | ||
### [.disabled](index.js#L183) | ||
### [.disabled](index.js#L210) | ||
@@ -156,3 +185,3 @@ Check if `prop` is disabled (falsey). | ||
### [.isTrue](index.js#L210) | ||
### [.isTrue](index.js#L237) | ||
@@ -182,3 +211,3 @@ Returns true if the value of `prop` is strictly `true`. | ||
### [.isFalse](index.js#L237) | ||
### [.isFalse](index.js#L264) | ||
@@ -208,3 +237,3 @@ Returns true if the value of `key` is strictly `false`. | ||
### [.isBoolean](index.js#L261) | ||
### [.isBoolean](index.js#L288) | ||
@@ -230,61 +259,27 @@ Return true if the value of key is either `true` or `false`. | ||
<br> | ||
## Related projects | ||
*** | ||
* [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://www.npmjs.com/package/base) | [homepage](https://github.com/node-base/base) | ||
* [cache-base](https://www.npmjs.com/package/cache-base): Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects. | [homepage](https://github.com/jonschlinkert/cache-base) | ||
* [config-cache](https://www.npmjs.com/package/config-cache): General purpose JavaScript object storage methods. | [homepage](https://github.com/jonschlinkert/config-cache) | ||
* [map-cache](https://www.npmjs.com/package/map-cache): Basic cache object for storing key-value pairs. | [homepage](https://github.com/jonschlinkert/map-cache) | ||
<br> | ||
## Contributing | ||
## Example app | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/option-cache/issues/new). | ||
Use options-cache in your javascript application: | ||
## Building docs | ||
```js | ||
var util = require('util'); | ||
var Options = require('options-cache'); | ||
Generate readme and API documentation with [verb](https://github.com/verbose/verb): | ||
function App(options) { | ||
Options.call(this, options); | ||
this.init(); | ||
} | ||
```sh | ||
$ npm i verb && npm run docs | ||
``` | ||
util.inherits(App, Options); | ||
Or, if [verb](https://github.com/verbose/verb) is installed globally: | ||
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 | ||
} | ||
}; | ||
```sh | ||
$ verb | ||
``` | ||
<br> | ||
*** | ||
<br> | ||
## Related | ||
* [cache-base](https://www.npmjs.com/package/cache-base): Generic object cache for node.js/javascript projects. | [homepage](https://github.com/jonschlinkert/cache-base) | ||
* [config-cache](https://www.npmjs.com/package/config-cache): General purpose JavaScript object storage methods. | [homepage](https://github.com/jonschlinkert/config-cache) | ||
* [engine-cache](https://www.npmjs.com/package/engine-cache): express.js inspired template-engine manager. | [homepage](https://github.com/jonschlinkert/engine-cache) | ||
* [helper-cache](https://www.npmjs.com/package/helper-cache): Easily register and get helper functions to be passed to any template engine or node.js… [more](https://www.npmjs.com/package/helper-cache) | [homepage](https://github.com/jonschlinkert/helper-cache) | ||
* [loader-cache](https://www.npmjs.com/package/loader-cache): Register loader functions that dynamically read, parse or otherwise transform file contents when the name… [more](https://www.npmjs.com/package/loader-cache) | [homepage](https://github.com/jonschlinkert/loader-cache) | ||
* [map-cache](https://www.npmjs.com/package/map-cache): Basic cache object for storing key-value pairs. | [homepage](https://github.com/jonschlinkert/map-cache) | ||
* [parser-cache](https://www.npmjs.com/package/parser-cache): Cache and load parsers, similiar to consolidate.js engines. | [homepage](https://github.com/jonschlinkert/parser-cache) | ||
## Contributing | ||
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/option-cache/issues/new). | ||
## Running tests | ||
@@ -298,15 +293,4 @@ | ||
## Coverage | ||
# Changelog | ||
As of October 29, 2015: | ||
```sh | ||
Statements : 100% (45/45) | ||
Branches : 100% (18/18) | ||
Functions : 100% (11/11) | ||
Lines : 100% (45/45) | ||
``` | ||
## Changelog | ||
**v3.0.0** | ||
@@ -327,14 +311,12 @@ | ||
+ [github/jonschlinkert](https://github.com/jonschlinkert) | ||
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
* [github/jonschlinkert](https://github.com/jonschlinkert) | ||
* [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
## License | ||
Copyright © 2015 Jon Schlinkert | ||
Released under the MIT license. | ||
Copyright © 2016 [Jon Schlinkert](https://github.com/jonschlinkert) | ||
Released under the [MIT license](https://github.com/jonschlinkert/option-cache/blob/master/LICENSE). | ||
*** | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 29, 2015._ | ||
<!-- deps:mocha --> | ||
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on February 23, 2016._ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
15447
275
1
6
308
+ Addedlazy-cache@1.0.4(transitive)
- Removedlazy-cache@0.2.7(transitive)
Updatedget-value@^2.0.3
Updatedlazy-cache@^1.0.3
Updatedset-value@^0.3.3
Updatedto-object-path@^0.3.0