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

config-cache

Package Overview
Dependencies
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

config-cache - npm Package Compare versions

Comparing version 4.0.0 to 5.0.0

426

index.js

@@ -10,20 +10,10 @@ /*!

var Base = require('class-extend');
var typeOf = require('kind-of');
var expander = require('expander');
var extend = require('extend-shallow');
var flatten = require('arr-flatten');
var Emitter = require('component-emitter');
var flatten = require('arr-flatten');
var clone = require('clone-deep');
var rest = require('array-rest');
var union = require('arr-union');
var hasOwnDeep = require('has-own-deep');
var union = require('array-union');
var omit = require('object.omit');
var set = require('set-value');
var get = require('get-value');
var has = require('has-value');
var forIn = require('for-in');
var Plasma = require('plasma');
var expand = expander.process;
var hasOwn = Object.prototype.hasOwnProperty;

@@ -43,13 +33,9 @@ /**

function Cache (cache) {
function Cache() {
Emitter.call(this);
this.cache = cache || {};
this.cache.data = this.cache.data || {};
this._ = this._ || {};
this._.plasma = new Plasma(this.cache.data);
this.cache = {};
}
Base.extend(Cache.prototype);
Cache.extend = Base.extend;
extend(Cache.prototype, Emitter.prototype);
Emitter(Cache.prototype);
Cache.mixin = mixin;

@@ -114,4 +100,2 @@ /**

*
* **Example**
*
* ```js

@@ -136,3 +120,2 @@ * cache.constant('site.title', 'Foo');

}
namespace = namespace || 'cache';

@@ -145,81 +128,5 @@ this[namespace] = this[namespace] || {};

/**
* Return the keys on `this.cache`.
* Add values to an array on the `cache`.
*
* ```js
* cache.keys();
* ```
*
* @return {Boolean}
* @api public
*/
Cache.prototype.keys = function(o) {
return Object.keys(o || this.cache);
};
/**
* Return true if `key` is an own, enumerable property
* of `this.cache` or the given `obj`.
*
* ```js
* cache.hasOwn([key]);
* ```
*
* @param {String} `key`
* @param {Object} `obj` Optionally pass an object to check.
* @return {Boolean}
* @api public
*/
Cache.prototype.hasOwn = function(key, o) {
return hasOwn.call(o || this.cache, key);
};
/*
* Return true if `key` exists in `cache`. Dot notation may
* be used for nested properties.
*
* **Example**
*
* ```js
* cache.exists('author.name');
* //=> true
* ```
*
* @param {String} `key`
* @return {Boolean}
* @api public
*/
Cache.prototype.exists = function(key, escape) {
return hasOwnDeep(this.cache, key, escape);
};
/*
* Return true if `property` exists and has a non-null value.
* Dot notation may be used for nested properties.
*
* **Example**
*
* ```js
* cache.has('author.name');
* //=> true
* ```
*
* @param {String} `property`
* @return {Boolean}
* @api public
*/
Cache.prototype.has = function(prop) {
return has(this.cache, prop);
};
/**
* Add values to an array on the `cache`. This method
* is chainable.
*
* **Example**
*
* ```js
* // config.cache['foo'] => ['a.hbs', 'b.hbs']

@@ -232,3 +139,2 @@ * cache

* ```
*
* @chainable

@@ -239,7 +145,6 @@ * @return {Object} `Cache` to enable chaining

Cache.prototype.union = function(key, array) {
Cache.prototype.union = function(key/*, array*/) {
if (typeof key !== 'string') {
throw new Error('config-cache#union expects `key` to be a string.');
}
var arr = this.get(key) || [];

@@ -252,3 +157,2 @@ var len = arguments.length - 1;

}
this.set(key, union(arr, flatten(args)));

@@ -263,4 +167,2 @@ this.emit('union', key);

*
* **Example**
*
* ```js

@@ -283,3 +185,2 @@ * cache

* ```
*
* @chainable

@@ -293,10 +194,8 @@ * @return {Object} `Cache` to enable chaining

var args = new Array(len);
for (var i = 0; i < len; i++) {
args[i] = arguments[i];
}
if (typeof args[0] === 'string') {
var o = this.get(args[0]) || {};
o = extend.apply(extend, union([o], rest(args)));
o = extend.apply(extend, union([o], args.slice(1)));
this.set(args[0], o);

@@ -312,139 +211,15 @@ this.emit('extend');

/**
* Clone the given `obj` or `cache`.
* Remove `keys` from the cache. If no value is
* specified the entire cache is reset.
*
* ```js
* cache.clone();
* cache.del();
* ```
*
* @param {Object} `obj` Optionally pass an object to clone.
* @return {Boolean}
* @api public
*/
Cache.prototype.clone = function(o) {
return clone(o || this.cache);
};
/**
* Return methods on `this.cache` or the given `obj`.
*
* ```js
* cache.methods('foo')
* //=> ['set', 'get', 'enable', ...]
* ```
*
* @param {Object} `obj`
* @return {Array}
* @api public
*/
Cache.prototype.methods = function(o) {
return methods(o || this.cache);
};
/**
* # Data methods
*
* > Methods for reading data files, processing template strings and
* extending the `cache.data` object.
*
* @api public
*/
/**
* Use [expander] to recursively expand template strings into
* their resolved values.
*
* **Example**
*
* ```js
* cache.process({a: '<%= b %>', b: 'c'});
* //=> {a: 'c', b: 'c'}
* ```
*
* @param {*} `lookup` Any value to process, usually strings with a
* cache template, like `<%= foo %>` or `${foo}`.
* @param {*} `opts` Options to pass to Lo-Dash `_.template`.
* @api public
*/
Cache.prototype.process = function(lookup, context) {
var len = arguments.length;
if (!len) {
lookup = context = this.cache.data;
} else {
context = context || this.cache.data;
if (typeOf(lookup) === 'object') {
context = extend({}, context, lookup);
}
}
var methods = this.methods(context);
var o = expand(context, lookup, {
imports: methods
});
if (!len) {
extend(this.cache.data, o);
}
return o;
};
/**
* If a `data` property is on the given `data` object
* (e.g. `data.data`, like when files named `data.json`
* or `data.yml` are used), the value of `data.data`'s
* is flattened to the root `data` object.
*
* @param {Object} `data`
* @return {Object} Returns the flattened object.
*/
Cache.prototype.flattenData = function(data, keys) {
keys = keys || 'data';
keys = !Array.isArray(keys) ? [keys] : keys;
var len = keys.length;
while (len--) {
if (this.hasOwn(keys[len], data)) {
extend(data, data[keys[len]]);
delete data[keys[len]];
}
}
return data;
};
/**
* Extend the `cache.data` object with the given data. This
* method is chainable.
*
* **Example**
*
* ```js
* cache
* .extendData({foo: 'bar'}, {baz: 'quux'});
* .extendData({fez: 'bang'});
* ```
*
* @chainable
* @return {Object} `Cache` to enable chaining
* @api public
*/
Cache.prototype.extendData = function() {
var len = arguments.length;
var args = new Array(len);
for (var i = 0; i < len; i++) {
args[i] = arguments[i];
}
if (typeof args[0] === 'string') {
this.extend.apply(this, ['data.' + args[0]].concat(rest(args)));
this.emit('extendData');
return this;
}
this.extend.apply(this, ['data'].concat(args));
this.emit('extendData');
Cache.prototype.del = function(keys) {
this.cache = keys ? omit(this.cache, keys) : {};
this.emit('del', keys);
return this;

@@ -454,169 +229,22 @@ };

/**
* Extend the `data` object with the value returned by [plasma].
* Mix `Cache` properties onto `obj`
*
* **Example:**
*
* ```js
* cache
* .plasma({foo: 'bar'}, {baz: 'quux'});
* .plasma({fez: 'bang'});
* ```
*
* See the [plasma] documentation for all available options.
*
* @param {Object|String|Array} `data` File path(s), glob pattern, or object of data.
* @param {Object} `options` Options to pass to plasma.
* @api public
* @param {[type]} obj [description]
* @return {[type]}
*/
Cache.prototype.plasma = function() {
return this._.plasma.load.apply(this._.plasma, arguments);
};
/**
* Extend the `cache.data` object with data from a JSON
* or YAML file, or by passing an object directly - glob
* patterns or file paths may be used.
*
* ```js
* cache
* .data({a: 'b'})
* .data({c: 'd'});
*
* console.log(config.cache);
* //=> {data: {a: 'b', c: 'd'}}
* ```
*
* When `true` is passed as the last argumemnt data will
* be processed by [expander] before extending `cache.data`.
*
* ```js
* cache.data({a: '<%= b %>', b: 'z'})
* //=> {data: {a: 'z', b: 'z'}}
* ```
*
* @param {Object|Array|String} `values` Values to pass to plasma.
* @param {Boolean} `process` If `true`,
* @return {Object} `Cache` to enable chaining
* @api public
*/
Cache.prototype.data = function() {
var len = arguments.length;
var args = new Array(len);
for (var i = 0; i < len; i++) {
args[i] = arguments[i];
function mixin(obj) {
var receiver = obj.constructor;
var provider = this;
for (var key in provider) {
receiver[key] = provider[key];
}
if (!len) {
return this.cache.data;
receiver.prototype = Object.create(provider.prototype);
for (var key in obj) {
receiver.prototype[key] = obj[key];
}
var o = {}, last;
// 1) when the last arg is `true`...
if (typeof args[len - 1] === 'boolean') {
last = args[len - 1];
args = args.slice(1);
}
extend(o, this.plasma.apply(this, args));
o = this.flattenData(o);
// 2) process data with expander
if (last) {
this.extendData(this.process(o));
return this;
}
this.extendData(o);
this.emit('data');
return this;
};
/**
* # Clearing the cache
*
* > Methods for clearing the cache, removing or reseting specific
* values on the cache.
*
* @section
*/
/**
* Omit properties from the `cache`.
*
* **Example:**
*
* ```js
* cache
* .omit('foo');
* .omit('foo', 'bar');
* .omit(['foo']);
* .omit(['foo', 'bar']);
* ```
*
* @chainable
* @return {Object} `Cache` to enable chaining
* @api public
*/
Cache.prototype.omit = function(keys) {
if (keys == null) return this;
keys = arrayify(keys);
this.cache = omit(this.cache, keys);
this.emit('omit', keys);
return this;
};
/**
* Remove `key` from the cache, or if no value is
* specified the entire cache is reset.
*
* **Example:**
*
* ```js
* cache.del();
* ```
*
* @chainable
* @api public
*/
Cache.prototype.del = function(key) {
if (key) {
delete this.cache[key];
this.emit('del', key);
} else {
this.cache = {};
this.emit('del');
}
};
/**
* Cast `val` to an array
*/
function arrayify(val) {
return Array.isArray(val) ? val : [val];
return receiver;
}
/**
* Utility function for concatenating array
* elements.
*/
function methods(o) {
var res = {};
forIn(o, function (val, key) {
if (typeof val === 'function') {
res[key] = val;
}
});
return res;
}
/**
* Expose `Cache`

@@ -623,0 +251,0 @@ */

34

package.json
{
"name": "config-cache",
"description": "General purpose JavaScript object storage methods.",
"version": "4.0.0",
"version": "5.0.0",
"homepage": "https://github.com/jonschlinkert/config-cache",
"author": {
"name": "Jon Schlinkert",
"url": "https://github.com/jonschlinkert"
},
"authors": [
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"maintainers": [
{
"name": "Jon Schlinkert",
"username": "jonschlinkert"
},
{
"name": "Brian Woodward",

@@ -27,6 +20,3 @@ "username": "doowb"

},
"license": {
"type": "MIT",
"url": "https://github.com/jonschlinkert/config-cache/blob/master/LICENSE"
},
"license": "MIT",
"files": [

@@ -44,17 +34,9 @@ "index.js"

"arr-flatten": "^1.0.1",
"arr-union": "^2.0.1",
"array-rest": "^0.1.1",
"class-extend": "^0.1.1",
"clone-deep": "^0.1.1",
"array-union": "^1.0.1",
"component-emitter": "^1.2.0",
"expander": "^0.3.3",
"extend-shallow": "^1.1.2",
"for-in": "^0.1.4",
"extend-shallow": "^1.1.4",
"get-value": "^1.1.4",
"has-own-deep": "^0.1.4",
"has-value": "^0.2.0",
"kind-of": "^1.1.0",
"kind-of": "^2.0.0",
"object.omit": "^1.1.0",
"plasma": "^0.8.2",
"set-value": "^0.1.6"
"set-value": "^0.2.0"
},

@@ -61,0 +43,0 @@ "devDependencies": {

@@ -5,6 +5,28 @@ # config-cache [![NPM version](https://badge.fury.io/js/config-cache.svg)](http://badge.fury.io/js/config-cache) [![Build Status](https://travis-ci.org/jonschlinkert/config-cache.svg)](https://travis-ci.org/jonschlinkert/config-cache)

## Breaking changes in 5.0!
Major breaking changes were made in 5.0!
In an effort to simplify the library, the following methods were removed:
* `clone`: use [clone-deep](https://github.com/jonschlinkert/clone-deep), example: `var obj = cloneDeep(config.cache)`
* `keys`: use `Object.keys(config.cache)`
* `omit`: use `.del()`
* `exists`: use `config.cache.hasOwnProperty()` or [has-value](https://github.com/jonschlinkert/has-value)
* `has`: use `config.cache.hasownProperty()` or [has-value](https://github.com/jonschlinkert/has-value)
* `hasOwn`: use `config.cache.hasOwnProperty()` or [has-value](https://github.com/jonschlinkert/has-value)
The following data methods were also removed, use [plasma-cache](https://github.com/jonschlinkert/plasma-cache)if you need these methods:
* `data`
* `process`
* `plasma`
* `extendData`
## Install
Install with [npm](https://www.npmjs.com/)
```bash
npm i config-cache --save
```sh
$ npm i config-cache --save
```

@@ -21,3 +43,3 @@

### [Cache](index.js#L42)
### [Cache](index.js#L32)

@@ -36,3 +58,3 @@ Initialize a new `Cache`

### [.set](index.js#L68)
### [.set](index.js#L54)

@@ -44,3 +66,3 @@ Assign `value` to `key` or return the value of `key`.

* `key` **{String}**
* `value` __{_}_*
* `value` **{*}**
* `expand` **{Boolean}**: Resolve template strings with [expander](https://github.com/tkellen/expander)

@@ -55,3 +77,3 @@ * `returns` **{Object}** `Cache`: to enable chaining

### [.get](index.js#L105)
### [.get](index.js#L91)

@@ -62,5 +84,5 @@ Return the stored value of `key`. Dot notation may be used to get [nested property values](https://github.com/jonschlinkert/get-value).

* `key` __{_}_*
* `key` **{*}**
* `escape` **{Boolean}**
* `returns` __{_}_*
* `returns` **{*}**

@@ -80,3 +102,3 @@ **Example**

### [.constant](index.js#L124)
### [.constant](index.js#L108)

@@ -88,3 +110,3 @@ Set a constant on the cache.

* `key` **{String}**
* `value` __{_}_*
* `value` **{*}**

@@ -97,66 +119,6 @@ **Example**

### [.keys](index.js#L151)
### [.union](index.js#L139)
Return the keys on `this.cache`.
Add values to an array on the `cache`.
* `returns` **{Boolean}**
**Example**
```js
cache.keys();
```
### [.hasOwn](index.js#L169)
Return true if `key` is an own, enumerable property of `this.cache` or the given `obj`.
**Params**
* `key` **{String}**
* `obj` **{Object}**: Optionally pass an object to check.
* `returns` **{Boolean}**
**Example**
```js
cache.hasOwn([key]);
```
### [.exists](index.js#L189)
Return true if `key` exists in `cache`. Dot notation may be used for nested properties.
**Params**
* `key` **{String}**
* `returns` **{Boolean}**
**Example**
```js
cache.exists('author.name');
//=> true
```
### [.has](index.js#L209)
Return true if `property` exists and has a non-null value. Dot notation may be used for nested properties.
**Params**
* `property` **{String}**
* `returns` **{Boolean}**
**Example**
```js
cache.has('author.name');
//=> true
```
### [.union](index.js#L233)
Add values to an array on the `cache`. This method is chainable.
* `returns` **{Object}** `Cache`: to enable chaining

@@ -175,3 +137,3 @@

### [.extend](index.js#L280)
### [.extend](index.js#L181)

@@ -202,145 +164,9 @@ Extend the `cache` with the given object. This method is chainable.

### [.clone](index.js#L312)
### [.del](index.js#L210)
Clone the given `obj` or `cache`.
Remove `keys` from the cache. If no value is specified the entire cache is reset.
**Params**
* `obj` **{Object}**: Optionally pass an object to clone.
* `returns` **{Boolean}**
**Example**
```js
cache.clone();
```
### [.methods](index.js#L329)
Return methods on `this.cache` or the given `obj`.
**Params**
* `obj` **{Object}**
* `returns` **{Array}**
**Example**
```js
cache.methods('foo')
//=> ['set', 'get', 'enable', ...]
```
### [Data methods](index.js#L342)
> Methods for reading data files, processing template strings and
extending the `cache.data` object.
### [.process](index.js#L359)
Use [expander](https://github.com/tkellen/expander)to recursively expand template strings into their resolved values.
**Params**
* `lookup` __{_}_*: Any value to process, usually strings with a cache template, like `<%= foo %>` or `${foo}`.
* `opts` __{_}_*: Options to pass to Lo-Dash ` _.template`.
**Example**
```js
cache.process({a: '<%= b %>', b: 'c'});
//=> {a: 'c', b: 'c'}
```
### [.extendData](index.js#L422)
Extend the `cache.data` object with the given data. This method is chainable.
* `returns` **{Object}** `Cache`: to enable chaining
**Example**
```js
cache
.extendData({foo: 'bar'}, {baz: 'quux'});
.extendData({fez: 'bang'});
```
### [.plasma](index.js#L459)
Extend the `data` object with the value returned by [plasma](https://github.com/jonschlinkert/plasma).
**Example:**
See the [plasma](https://github.com/jonschlinkert/plasma)documentation for all available options.
**Params**
* `data` **{Object|String|Array}**: File path(s), glob pattern, or object of data.
* `options` **{Object}**: Options to pass to plasma.
**Example**
```js
cache
.plasma({foo: 'bar'}, {baz: 'quux'});
.plasma({fez: 'bang'});
```
### [.data](index.js#L491)
Extend the `cache.data` object with data from a JSON or YAML file, or by passing an object directly - glob patterns or file paths may be used.
When `true` is passed as the last argumemnt data will
be processed by [expander](https://github.com/tkellen/expander)before extending `cache.data`.
**Params**
* `values` **{Object|Array|String}**: Values to pass to plasma.
* `process` **{Boolean}**: If `true`,
* `returns` **{Object}** `Cache`: to enable chaining
**Examples**
```js
cache
.data({a: 'b'})
.data({c: 'd'});
console.log(config.cache);
//=> {data: {a: 'b', c: 'd'}}
```
```js
cache.data({a: '<%= b %>', b: 'z'})
//=> {data: {a: 'z', b: 'z'}}
```
### [.omit](index.js#L553)
Omit properties from the `cache`.
**Example:**
* `returns` **{Object}** `Cache`: to enable chaining
**Example**
```js
cache
.omit('foo');
.omit('foo', 'bar');
.omit(['foo']);
.omit(['foo', 'bar']);
```
### [.del](index.js#L575)
Remove `key` from the cache, or if no value is specified the entire cache is reset.
**Example:**
**Example**
```js
cache.del();

@@ -383,7 +209,8 @@ ```

* [get-value](https://github.com/jonschlinkert/get-value): Use property paths (` a.b.c`) get a nested value from an object.
* [has-value](https://github.com/jonschlinkert/has-value): Returns true if a value exists, false if empty. Works with deeply nested values using… [more](https://github.com/jonschlinkert/has-value)
* [helper-cache](https://github.com/jonschlinkert/helper-cache): Easily register and get helper functions to be passed to any template engine or node.js… [more](https://github.com/jonschlinkert/helper-cache)
* [has-value](https://github.com/jonschlinkert/has-value): Returns true if a value exists, false if empty. Works with deeply nested values using… [more](https://github.com/jonschlinkert/has-value)
* [loader-cache](https://github.com/jonschlinkert/loader-cache): Register loader functions that dynamically read, parse or otherwise transform file contents when the name… [more](https://github.com/jonschlinkert/loader-cache)
* [map-cache](https://github.com/jonschlinkert/map-cache): Basic cache object for storing key-value pairs.
* [option-cache](https://github.com/jonschlinkert/option-cache): Simple API for managing options in JavaScript applications.
* [plasma-cache](https://github.com/jonschlinkert/plasma-cache): Object cache for Plasma.
* [parser-cache](https://github.com/jonschlinkert/parser-cache): Cache and load parsers, similiar to consolidate.js engines.

@@ -400,4 +227,4 @@ * [set-value](https://github.com/jonschlinkert/set-value): Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.

```bash
npm i -d && npm test
```sh
$ npm i -d && npm test
```

@@ -414,3 +241,3 @@

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

@@ -420,2 +247,2 @@

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on May 07, 2015._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on May 31, 2015._
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