Socket
Socket
Sign inDemoInstall

cache-base

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cache-base - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

.verb.md

257

index.js

@@ -1,17 +0,16 @@

/*!
* cache-base <https://github.com/jonschlinkert/cache-base>
*
* Copyright (c) 2014 Jon Schlinkert, contributors.
* Licensed under the MIT license.
*/
'use strict';
var util = require('util');
var typeOf = require('kind-of');
var forIn = require('for-in');
var forOwn = require('for-own');
var merge = require('mixin-deep');
var Options = require('option-cache');
var slice = require('array-slice');
var get = require('get-value');
var _ = require('lodash');
/**
* Expose `Cache`
*/
module.exports = Cache;
/**

@@ -31,6 +30,8 @@ * Create a new instance of `Cache`

function Cache(cache) {
Options.call(this);
this.cache = cache || {};
this.options = {};
}
util.inherits(Cache, Options);
/**

@@ -53,8 +54,7 @@ * Assign `value` to `key` or return the value of `key`.

Cache.prototype.set = function (key, value) {
if (arguments.length === 1 && isObject(key)) {
this.extend(key);
return this;
if (typeOf(key) === 'object') {
_.extend(this.cache, key);
} else {
this.cache[key] = value;
}
this.cache[key] = value;
return this;

@@ -79,86 +79,34 @@ };

if (!key) {
return this.cache;
return _.cloneDeep(this.cache);
}
return get(this.cache, key);
if (/\./.test(key)) {
return get(this.cache, key, true);
}
return this.cache[key];
};
/**
* Check if `key` is enabled (truthy).
/*
* Return `true` if the element exists. Dot notation
* may be used for nested properties.
*
* ```js
* cache.enabled('foo')
* // => false
*
* cache.enable('foo')
* cache.enabled('foo')
* // => true
* ```
*
* @param {String} `key`
* @return {Boolean}
* @api public
*/
Cache.prototype.enabled = function (key) {
return !!this.get(key);
};
/**
* Check if `key` is disabled (falsey).
*
* ```js
* app.disabled('foo');
* // => true
*
* app.enable('foo');
* app.disabled('foo');
* // => false
* ```
*
* @param {String} `key`
* @return {Boolean} Returns true if `key` is disabled.
* @api public
*/
Cache.prototype.disabled = function (key) {
return !this.get(key);
};
/**
* Enable `key`.
*
* **Example**
*
* ```js
* app.enable('foo');
* app.exists('author.name');
* //=> true
* ```
*
* @param {String} `key`
* @return {Object} `Cache` to enable chaining
* @return {Boolean}
* @api public
*/
Cache.prototype.enable = function (key) {
return this.set(key, true);
Cache.prototype.exists = function(key) {
if (this.hasOwn(key)) {
return true;
}
return get(this.cache, key, true) !== undefined;
};
/**
* Disable `key`.
*
* **Example**
*
* ```js
* app.disable('foo');
* ```
*
* @param {String} `key` The option to disable.
* @return {Object} `Cache` to enable chaining;
* @api public
*/
Cache.prototype.disable = function (key) {
return this.set(key, false);
};
/**
* Extend the `cache` with the given object.

@@ -179,14 +127,14 @@ *

Cache.prototype.extend = function() {
var args = [].slice.call(arguments);
var rest = args.slice(1);
Cache.prototype.extend = function(val) {
var args = [].concat.apply([], arguments);
if (typeof args[0] === 'string') {
var o = this.get(args[0]) || {};
o = extend.apply(extend, [o].concat(rest));
this.set(args[0], o);
if (typeof val === 'string') {
var rest = args.slice(1);
var o = this.get(val) || {};
o = _.extend.apply(_, [o].concat(rest));
this.cache[val] = o;
return this;
}
extend.apply(extend, [this.cache].concat(args));
_.extend.apply(_, [this.cache].concat(args));
return this;

@@ -211,14 +159,14 @@ };

Cache.prototype.merge = function() {
var args = [].slice.call(arguments);
var rest = args.slice(1);
Cache.prototype.merge = function(val) {
var args = [].concat.apply([], arguments);
if (typeof args[0] === 'string') {
var o = this.get(args[0]) || {};
o = merge.apply(merge, [o].concat(rest));
this.set(args[0], o);
if (typeof val === 'string') {
var rest = args.slice(1);
var o = this.get(val) || {};
o = _.merge.apply(_, [o].concat(rest));
this.cache[val] = o;
return this;
}
merge.apply(merge, [this.cache].concat(args));
_.merge.apply(_, [this.cache].concat(args));
return this;

@@ -243,3 +191,3 @@ };

}
return forOwn(o, fn, thisArg || this);
return _.forOwn(o, fn, thisArg || this);
};

@@ -282,3 +230,3 @@

forIn(o, function (val, key) {
_.forIn(o, function (val, key) {
if (typeof val === 'function') {

@@ -288,2 +236,3 @@ fns[key] = val;

});
return fns;

@@ -305,7 +254,7 @@ };

Cache.prototype.has = function (o, lookup) {
if (arguments.length === 1) {
return !!get(this.cache, o);
Cache.prototype.has = function (val, lookup) {
if (arguments.length === 1 && typeof val === 'string') {
return get(this.cache, val) !== undefined;
}
return !!get(o, lookup);
return get(val, lookup) !== undefined;
};

@@ -338,79 +287,61 @@

/**
* Remove `key` from the cache, or if no value is
* specified the entire cache is reset.
* Clone the given `obj` or `cache`.
*
* **Example:**
*
* ```js
* app.clear();
* app.clone();
* ```
*
* @param {String} `key` The property to remove.
* @param {Object} `obj` Optionally pass an object to clone.
* @return {Boolean}
* @api public
*/
Cache.prototype.clear = function (key) {
if (key) {
delete this.cache[key];
} else {
this.cache = {};
}
Cache.prototype.clone = function(o) {
return _.cloneDeep(o || this.cache);
};
/**
* Extend the target `obj` with properties from other
* objects.
* Delete a property or array of properties from the cache then
* re-save the cache.
*
* @param {Object} `obj` The target object. Pass an empty object to shallow clone.
* @param {Objects}
* @return {Object}
* @api private
* ```js
* app.omit('foo');
* // or
* app.omit(['foo', 'bar']);
* ```
*
* @param {String|Array} `key` The key(s) to omit from the cache
* @api public
*/
function extend(o) {
var args = [].slice.call(arguments, 1);
if (o == null) {
return {};
}
var len = args.length;
Cache.prototype.omit = function(keys) {
keys = [].concat.apply([], arguments);
for (var i = 0; i < len; i++) {
var obj = args[i];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
o[key] = obj[key];
}
}
for (var i = 0; i < keys.length; i++) {
delete this.cache[keys[i]];
}
return o;
}
/**
* Get the type of a value.
*
* @param {*} `value`
* @api private
*/
return this;
};
function isObject(value) {
return typeOf(value) === 'object';
}
/**
* Return `true` if `value` is an array.
* Remove `key` from the cache, or if no value is
* specified the entire cache is reset.
*
* @param {*} `value`
* @api private
* **Example:**
*
* ```js
* app.clear();
* ```
*
* @param {String} `key` The property to remove.
* @api public
*/
function isArray(value) {
return Array.isArray(value) &&
typeOf(value) === 'array';
}
/**
* Expose `Cache`
*/
module.exports = Cache;
Cache.prototype.clear = function (key) {
if (key) {
delete this.cache[key];
} else {
this.cache = {};
}
};
{
"name": "cache-base",
"description": "Basic, general purpose object cache for node.js/javascript projects.",
"version": "0.1.0",
"version": "0.2.0",
"homepage": "https://github.com/jonschlinkert/cache-base",

@@ -40,13 +40,11 @@ "author": {

"mocha": "*",
"should": "^4.0.4",
"verb": ">= 0.2.6",
"verb-tag-jscomments": "^0.2.0"
"should": "^4.0.4"
},
"dependencies": {
"for-in": "^0.1.3",
"for-own": "^0.1.2",
"array-slice": "^0.2.2",
"get-value": "^0.2.1",
"kind-of": "^0.1.0",
"mixin-deep": "^0.1.0"
"lodash": "^2.4.1",
"option-cache": "^0.1.4"
}
}

@@ -1,10 +0,10 @@

# simple-cache [![NPM version](https://badge.fury.io/js/simple-cache.png)](http://badge.fury.io/js/simple-cache)
# cache-base [![NPM version](https://badge.fury.io/js/cache-base.svg)](http://badge.fury.io/js/cache-base)
> Basic, general purpose object hash, for node.js/javascript projects.
> Basic, general purpose object cache for node.js/javascript projects.
## Install
#### Install with [npm](npmjs.org):
### Install with [npm](npmjs.org)
```bash
npm i simple-cache --save-dev
npm i cache-base --save
```

@@ -14,143 +14,80 @@

```js
var Config = require('simple-cache');
var config = new Config();
```
Create an instance:
## API
### [Cache](index.js#L29)
Initialize a new `Cache`
* `obj` **{Object}**: Optionally pass an object to initialize with.
```js
var Cache = require('cache-base');
var cache = new Cache();
```
### [.option](index.js#L50)
**Inherit**
Set or get an option.
* `key` **{String}**: The option name.
* `value` **{*}**: The value to set.
* `returns` **{*|Object}**: Returns `value` if `key` is supplied, or `Cache` for chaining when an option is set.
```js
cache.option('a', true)
cache.option('a')
// => true
```
var util = require('util');
var Cache = require('cache-base');
### [.set](index.js#L110)
function App() {
Cache.call(this);
}
Assign `value` to `key` or return the value of `key`.
* `key` **{String}**
* `value` **{*}**
* `expand` **{Boolean}**: Resolve template strings with [expander]
* `returns` **{Cache}**: for chaining
```js
cache.set(key, value);
util.inherits(App, Cache);
```
If `expand` is defined as true, the value will be set using [expander].
**Example usage**
**Examples:**
```js
// as a key-value pair
cache.set('a', {b: 'c'});
var app = new App();
// or as an object
cache.set({a: {b: 'c'}});
app.set('a', 'b');
app.get('a');
//=> 'b'
// chaining is possible
cache
.set({a: {b: 'c'}})
.set('d', 'e');
app.enable('abc');
console.log(app.enabled('abc'));
//=> 'true'
```
Expand template strings with expander:
## API
## [Cache](index.js#L29)
```js
cache.set('a', {b: '${c}', c: 'd'}, true);
```
Create a new instance of `Cache`
Visit the [expander] docs for more info.
* `cache` **{Object}**: Optionally pass an object to initialize with.
[expander]: https://github.com/tkellen/expander
[getobject]: https://github.com/cowboy/node-getobject
### [.get](index.js#L147)
Return the stored value of `key`. If `key` is not defined, the `cache` is returned.
* `key` **{*}**
* `create` **{Boolean}**
* `returns`: {*}
If the value does **not** exist on the cache, you may pass
`true` as a second parameter to tell [getobject] to initialize
the value as an empty object.
```js
cache.set('foo', 'bar');
cache.get('foo');
// => "bar"
var app = new Cache();
```
### [.process](index.js#L172)
## [.set](index.js#L52)
Use [expander] to recursively expand template strings into their resolved values.
Assign `value` to `key` or return the value of `key`.
* `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'}
```
### [.enabled](index.js#L214)
Check if `key` is enabled (truthy).
* `key` **{String}**
* `returns`: {Boolean}
* `value` **{*}**
* `returns` **{Cache}**: for chaining
```js
cache.enabled('foo')
// => false
app.set(key, value);
cache.enable('foo')
cache.enabled('foo')
// => true
// extend
app.set({a: 'b'});
```
### [.disabled](index.js#L236)
## [.get](index.js#L75)
Check if `key` is disabled.
Return the stored value of `key`. If `key` is not defined, the `cache` is returned.
* `key` **{String}**
* `returns`: {Boolean}
```js
cache.disabled('foo')
// => true
cache.enable('foo')
cache.disabled('foo')
// => false
app.set('foo', 'bar');
app.get('foo');
// => "bar"
```
### [.enable](index.js#L255)
## [.exists](index.js#L101)
Enable `key`.
Return `true` if the element exists. Dot notation may be used for nested properties.
* `key` **{String}**
* `returns` **{Cache}**: for chaining
* `returns`: {Boolean}

@@ -160,11 +97,11 @@ **Example**

```js
cache.enable('foo');
app.exists('author.name');
//=> true
```
### [.disable](index.js#L274)
## [.extend](index.js#L124)
Disable `key`.
Extend the `cache` with the given object.
* `key` **{String}**
* `returns` **{Cache}**: for chaining
* `returns` **{Object}** `Cache`: to enable chaining.

@@ -174,10 +111,12 @@ **Example**

```js
cache.disable('foo');
app
.extend({a: 'b'}, {c: 'd'});
.extend('e', {f: 'g'});
```
### [.union](index.js#L320)
## [.merge](index.js#L155)
Add values to an array on the `cache`. This method is chainable.
Deep merge an object onto the `cache`.
* `returns` **{Cache}**: for chaining
* `returns` **{Object}** `Cache`: to enable chaining.

@@ -187,87 +126,53 @@ **Example**

```js
// config.cache['foo'] => ['a.hbs', 'b.hbs']
cache
.union('foo', ['b.hbs', 'c.hbs'], ['d.hbs']);
.union('foo', ['e.hbs', 'f.hbs']);
// config.cache['foo'] => ['a.hbs', 'b.hbs', 'c.hbs', 'd.hbs', 'e.hbs', 'f.hbs']
app.merge({a: {one: 'one'}}, {a: {two: 'two'}});
console.log(app.get('a'));
//=> {a: {one: 'one', two: 'two'}}
```
### [.defaults](index.js#L362)
## [.forOwn](index.js#L182)
Extend the `cache` with the given object. This method is chainable.
Return the keys on `obj` or `this.cache`.
* `returns` **{Cache}**: for chaining
* `obj` **{Object}**: Optionally pass an object.
* `returns` **{Array}**: Array of keys.
**Example**
```js
cache
.defaults({foo: 'bar'}, {baz: 'quux'});
.defaults({fez: 'bang'});
app.forOwn();
```
Or define the property to defaults:
## [.keys](index.js#L202)
```js
cache
// defaults `cache.a`
.defaults('a', {foo: 'bar'}, {baz: 'quux'})
// defaults `cache.b`
.defaults('b', {fez: 'bang'})
// defaults `cache.a.b.c`
.defaults('a.b.c', {fez: 'bang'});
```
Return the keys on `obj` or `this.cache`.
### [.extend](index.js#L406)
* `obj` **{Object}**: Optionally pass an object.
* `returns` **{Array}**: Array of keys.
Extend the `cache` with the given object. This method is chainable.
* `returns` **{Cache}**: for chaining
**Example**
```js
cache
.extend({foo: 'bar'}, {baz: 'quux'});
.extend({fez: 'bang'});
app.keys();
```
Or define the property to extend:
## [.functions](index.js#L220)
```js
cache
// extend `cache.a`
.extend('a', {foo: 'bar'}, {baz: 'quux'})
// extend `cache.b`
.extend('b', {fez: 'bang'})
// extend `cache.a.b.c`
.extend('a.b.c', {fez: 'bang'});
```
Return an object of only the properties on `this.cache` or the given `obj` that have function values.
### [.merge](index.js#L438)
* `obj` **{Object}**
* `returns`: {Array}
Extend the cache with the given object. This method is chainable.
* `returns` **{Cache}**: for chaining
**Example**
```js
cache
.merge({foo: 'bar'}, {baz: 'quux'});
.merge({fez: 'bang'});
app.functions('foo')
//=> {set: [function], get: [function], functions: [function]}
```
### [.keys](index.js#L462)
## [.has](index.js#L246)
Return the keys on `this.cache`.
Return true if a deep property is on the given object or `this.cache`.
* `returns`: {Boolean}
* `obj` **{Object}**: Optionally pass an object.
* `returns` **{String}** `lookup`: Prop string to use for the lookup, e.g. `a.b`
```js
cache.keys();
app.has('a.b.c');
```
### [.hasOwn](index.js#L481)
## [.hasOwn](index.js#L269)

@@ -281,6 +186,8 @@ Return true if `key` is an own, enumerable property of `this.cache` or the given `obj`.

```js
cache.hasOwn([key]);
app.hasOwn(key);
// or
app.hasOwn(obj, key);
```
### [.clone](index.js#L498)
## [.clone](index.js#L289)

@@ -293,69 +200,29 @@ Clone the given `obj` or `cache`.

```js
cache.clone();
app.clone();
```
### [.methods](index.js#L516)
## [.omit](index.js#L307)
Return methods on `this.cache` or the given `obj`.
Delete a property or array of properties from the cache then re-save the cache.
* `obj` **{Object}**
* `returns`: {Array}
* `key` **{String|Array}**: The key(s) to omit from the cache
```js
cache.methods('foo')
//=> ['set', 'get', 'enable', ...]
app.omit('foo');
// or
app.omit(['foo', 'bar']);
```
### [.each](index.js#L535)
## [.clear](index.js#L331)
Call `fn` on each property in `this.cache`.
Remove `key` from the cache, or if no value is specified the entire cache is reset.
* `fn` **{Function}**
* `obj` **{Object}**: Optionally pass an object to iterate over.
* `returns` **{Object}**: Resulting object.
* `key` **{String}**: The property to remove.
```js
cache.each(fn, obj);
```
### [.visit](index.js#L560)
Traverse each _own property_ of `this.cache` or the given object, recursively calling `fn` on child objects.
* `obj` **{Object|Function}**: Optionally pass an object.
* `fn` **{Function}**
* `returns` **{Object}**: Return the resulting object.
```js
cache.visit(obj, fn);
```
### [.Clearing the cache](index.js#L605)
> Methods for clearing the cache, removing or reseting specific values on the cache.
* `returns` **{Cache}**: for chaining
Omit properties and their from the `cache`.
**Example:**
```js
cache
.omit('foo');
.omit('foo', 'bar');
.omit(['foo']);
.omit(['foo', 'bar']);
app.clear();
```
### [.clear](index.js#L626)
Remove `key` from the cache, or if no value is specified the entire cache is reset.
**Example:**
```js
cache.clear();
```
## Author

@@ -369,3 +236,3 @@

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

@@ -375,2 +242,2 @@

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on August 27, 2014._
_This file was generated by [verb](https://github.com/assemble/verb) on November 15, 2014._
/*!
* config-cache <https://github.com/jonschlinkert/config-cache>
* cache-base <https://github.com/jonschlinkert/cache-base>
*

@@ -12,13 +12,18 @@ * Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors.

var Cache = require('..');
var app;
describe('Cache', function () {
describe('app.forOwn()', function () {
beforeEach(function() {
app = new Cache();
});
describe('constructor:', function () {
it('when new Cache() is defined:', function () {
var config = new Cache({
var app = new Cache({
one: 1,
two: 2
});
config.get('one').should.eql(1);
config.get('two').should.eql(2);
config.should.be.instanceOf(Cache);
app.get('one').should.eql(1);
app.get('two').should.eql(2);
app.should.be.instanceOf(Cache);
});

@@ -28,8 +33,8 @@ });

describe('keys():', function () {
var config = new Cache();
var app = new Cache();
it('should return the keys of properties on the cache.', function () {
config.set('a', 1);
config.set('b', 2);
config.set('c', 3);
config.keys().should.eql(['a', 'b', 'c']);
app.set('a', 1);
app.set('b', 2);
app.set('c', 3);
app.keys().should.eql(['a', 'b', 'c']);
});

@@ -39,6 +44,6 @@ });

describe('get/set:', function () {
var config = new Cache();
var app = new Cache();
afterEach(function() {
config.clear();
app.clear();
});

@@ -48,4 +53,4 @@

it('should set a new property with the given value', function () {
config.set('one', 1);
config.get('one').should.eql(1);
app.set('one', 1);
app.get('one').should.eql(1);
});

@@ -56,9 +61,9 @@ });

it('should update an existing property with the given value', function () {
config.set('one', 2);
config.get('one').should.eql(2);
app.set('one', 2);
app.get('one').should.eql(2);
});
it('should get the given property', function () {
config.set('a', 'b');
config.get('a').should.eql('b');
app.set('a', 'b');
app.get('a').should.eql('b');
});

@@ -65,0 +70,0 @@ });

@@ -12,28 +12,43 @@ /*!

var should = require('should');
var Config = require('..');
var config = new Config();
var Cache = require('..');
var app;
describe('config extend', function () {
afterEach(function() {
config.clear();
describe('app.forOwn()', function () {
beforeEach(function() {
app = new Cache();
});
describe('.extend()', function() {
it('should extend the `cache` with a value.', function() {
config.extend({a: 'b'});
config.get('a').should.equal('b');
it('should extend the `cache` object with an object.', function() {
app.extend({a: 'b'});
app.get('a').should.equal('b');
});
it('should extend the `cache` with an object.', function() {
config
it('should extend the given object with a key/value pair.', function() {
app.set('a', {b: 'c'});
app.extend('a', {d: 'e'});
app.get('a').should.eql({b: 'c', d: 'e'});
});
it('should extend the `cache` object with a list of values.', function() {
app.extend({a: 'b'}, {c: 'd'});
app.get().should.eql({a: 'b', c: 'd'});
});
it('should extend the `cache` object with an array of values.', function() {
app.extend([{a: 'b'}, {c: 'd'}]);
app.get().should.eql({a: 'b', c: 'd'});
});
it('should extend the `cache` object a mixture of list values and array values.', function() {
app.extend({a: 'b'}, [{c: 'd'}, {e: 'f'}]);
app.get().should.eql({a: 'b', c: 'd', e: 'f'});
});
it('should be chainable.', function() {
app
.extend({x: 'x', y: 'y', z: 'z'})
.extend({a: 'a', b: 'b', c: 'c'});
config.get().should.have.property('a');
config.get().should.have.property('b');
config.get().should.have.property('c');
config.get().should.have.property('x');
config.get().should.have.property('y');
config.get().should.have.property('z');
app.get().should.have.properties('a', 'b', 'c', 'x', 'y', 'z');
});

@@ -43,13 +58,13 @@ });

describe('when the same property is set more than once.', function() {
it('should extend the `cache` with the last value defined.', function() {
config.extend({a: 'B'}, {a: 'C'});
config.get('a').should.equal('C');
it('should extend the `cache` object with the last value defined.', function() {
app.extend({a: 'B'}, {a: 'C'});
app.get('a').should.equal('C');
});
it('should extend the `cache` with the last value defined.', function() {
config
it('should extend the `cache` object with the last value defined.', function() {
app
.extend({a: 'B'})
.extend({a: 'C'});
config.get('a').should.equal('C');
app.get('a').should.equal('C');
});

@@ -60,25 +75,25 @@ });

it('should extend that property on the cache.', function() {
config
app
.extend('foo', {x: 'x', y: 'y', z: 'z'})
.extend('bar', {a: 'a', b: 'b', c: 'c'});
config.get('bar').should.have.property('a');
config.get('bar').should.have.property('b');
config.get('bar').should.have.property('c');
config.get('foo').should.have.property('x');
config.get('foo').should.have.property('y');
config.get('foo').should.have.property('z');
app.get('bar').should.have.property('a');
app.get('bar').should.have.property('b');
app.get('bar').should.have.property('c');
app.get('foo').should.have.property('x');
app.get('foo').should.have.property('y');
app.get('foo').should.have.property('z');
});
it('should extend the `cache.data` object.', function() {
config
app
.extend('data', {x: 'x', y: 'y', z: 'z'})
.extend('data', {a: 'a', b: 'b', c: 'c'});
config.get('data').should.have.property('a');
config.get('data').should.have.property('b');
config.get('data').should.have.property('c');
config.get('data').should.have.property('x');
config.get('data').should.have.property('y');
config.get('data').should.have.property('z');
app.get('data').should.have.property('a');
app.get('data').should.have.property('b');
app.get('data').should.have.property('c');
app.get('data').should.have.property('x');
app.get('data').should.have.property('y');
app.get('data').should.have.property('z');
});

@@ -89,11 +104,11 @@ });

it('should extend the cache with a key-value pair.', function () {
config.extend('a', {b: 'c'});
config.hasOwn('a').should.be.true;
config.cache.should.have.property('a', {b: 'c'});
app.extend('a', {b: 'c'});
app.hasOwn('a').should.be.true;
app.cache.should.have.property('a', {b: 'c'});
});
it('should extend the cache with an object.', function () {
config.extend({a: 'b', c: 'd'});
config.hasOwn('a').should.be.true;
config.hasOwn('c').should.be.true;
app.extend({a: 'b', c: 'd'});
app.hasOwn('a').should.be.true;
app.hasOwn('c').should.be.true;
});

@@ -104,37 +119,37 @@ });

// it('should extend that property on the cache.', function() {
// config
// app
// .extend('foo', {xyz: {x: 'x', y: 'y', z: 'z'}})
// .extend('bar', {xyz: {a: 'a', b: 'b', c: 'c'}});
// config.get('bar.xyz').should.have.property('a');
// config.get('bar.xyz').should.have.property('b');
// config.get('bar.xyz').should.have.property('c');
// config.get('foo.xyz').should.have.property('x');
// config.get('foo.xyz').should.have.property('y');
// config.get('foo.xyz').should.have.property('z');
// app.get('bar.xyz').should.have.property('a');
// app.get('bar.xyz').should.have.property('b');
// app.get('bar.xyz').should.have.property('c');
// app.get('foo.xyz').should.have.property('x');
// app.get('foo.xyz').should.have.property('y');
// app.get('foo.xyz').should.have.property('z');
// config.cache.bar.should.have.property('xyz');
// config.cache.bar.should.have.property('xyz');
// config.cache.bar.should.have.property('xyz');
// config.cache.foo.should.have.property('xyz');
// config.cache.foo.should.have.property('xyz');
// config.cache.foo.should.have.property('xyz');
// app.cache.bar.should.have.property('xyz');
// app.cache.bar.should.have.property('xyz');
// app.cache.bar.should.have.property('xyz');
// app.cache.foo.should.have.property('xyz');
// app.cache.foo.should.have.property('xyz');
// app.cache.foo.should.have.property('xyz');
// });
// it('should extend deep properties.', function() {
// config.extend('a.b.c.d.xyz', {x: 'x', y: 'y', z: 'z'})
// app.extend('a.b.c.d.xyz', {x: 'x', y: 'y', z: 'z'})
// config.get('a.b.c.d.xyz').should.have.property('x');
// config.get('a.b.c.d.xyz').should.have.property('y');
// config.get('a.b.c.d.xyz').should.have.property('z');
// app.get('a.b.c.d.xyz').should.have.property('x');
// app.get('a.b.c.d.xyz').should.have.property('y');
// app.get('a.b.c.d.xyz').should.have.property('z');
// config.cache.a.b.c.d.should.have.property('xyz');
// config.cache.a.b.c.d.should.have.property('xyz');
// config.cache.a.b.c.d.should.have.property('xyz');
// app.cache.a.b.c.d.should.have.property('xyz');
// app.cache.a.b.c.d.should.have.property('xyz');
// app.cache.a.b.c.d.should.have.property('xyz');
// config.cache.a.b.c.d.xyz.should.have.property('x');
// config.cache.a.b.c.d.xyz.should.have.property('x');
// config.cache.a.b.c.d.xyz.should.have.property('x');
// app.cache.a.b.c.d.xyz.should.have.property('x');
// app.cache.a.b.c.d.xyz.should.have.property('x');
// app.cache.a.b.c.d.xyz.should.have.property('x');
// });
// });
});
/*!
* storage <https://github.com/jonschlinkert/storage>
* cache-base <https://github.com/jonschlinkert/cache-base>
*

@@ -10,15 +10,18 @@ * Copyright (c) 2014 Jon Schlinkert, contributors.

var assert = require('assert');
var should = require('should');
var Storage = require('..');
var storage = new Storage();
var Cache = require('..');
var app;
describe('.forOwn()', function () {
describe('app.forOwn()', function () {
beforeEach(function() {
app = new Cache();
});
it('should loop through all properties on the cache.', function () {
var o = {a: {b: 'c'}, d: {e: 'f'}, g: {h: 'i'}};
storage.extend(o);
app.extend(o);
var values = [];
var keys = [];
storage.forOwn(function (value, key, obj) {
app.forOwn(function (value, key, obj) {
o.should.eql(obj);

@@ -38,3 +41,3 @@ keys.push(key);

storage.forOwn(obj, function (value, key, o) {
app.forOwn(obj, function (value, key, o) {
o.should.eql(obj);

@@ -50,4 +53,4 @@ keys.push(key);

it('should expose `this` object.', function () {
storage.extend({a: {b: 'c'}, d: {e: 'f'}, g: {h: 'i'}});
storage.forOwn(function (value, key, obj) {
app.extend({a: {b: 'c'}, d: {e: 'f'}, g: {h: 'i'}});
app.forOwn(function (value, key, obj) {
this.cache.should.have.property('a');

@@ -58,4 +61,4 @@ });

it('should allow custom `thisArg` to be passed.', function () {
storage.extend({a: {b: 'c'}, d: {e: 'f'}, g: {h: 'i'}});
storage.forOwn(function (value, key, obj) {
app.extend({a: {b: 'c'}, d: {e: 'f'}, g: {h: 'i'}});
app.forOwn(function (value, key, obj) {
this.should.have.property('foo', 'b');

@@ -62,0 +65,0 @@ }, {foo: 'b'});

/*!
* config-cache <https://github.com/jonschlinkert/config-cache>
* cache-base <https://github.com/jonschlinkert/cache-base>
*

@@ -11,16 +11,21 @@ * Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors.

var should = require('should');
var Config = require('..');
var config = new Config();
var Cache = require('..');
var app;
describe('config functions', function() {
describe('app.functions()', function () {
beforeEach(function() {
app = new Cache();
});
describe('.functions()', function() {
it('should be object.', function() {
config.functions(config).should.be.an.object;
app.functions(app).should.be.an.object;
});
it('should return the functions on an object.', function() {
config.functions(config).should.have.property('set');
config.functions(config).should.have.property('get');
app.functions(app).should.have.property('set');
app.functions(app).should.have.property('get');
});
});
});
/*!
* config-cache <https://github.com/jonschlinkert/config-cache>
* cache-base <https://github.com/jonschlinkert/cache-base>
*

@@ -12,9 +12,9 @@ * Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors.

var should = require('should');
var Config = require('..');
var config = new Config();
var Cache = require('..');
var app;
describe('config get/set', function () {
afterEach(function() {
config.clear();
describe('app.get()/app.set()', function () {
beforeEach(function() {
app = new Cache();
});

@@ -24,35 +24,35 @@

it('should set a value', function () {
config.set('a', 'b');
config.get('a').should.equal('b');
app.set('a', 'b');
app.get('a').should.equal('b');
});
it('should set properties on the `cache` object.', function () {
config.set('a', 'b');
config.cache.a.should.equal('b');
app.set('a', 'b');
app.cache.a.should.equal('b');
});
it('should allow an object to be set directly.', function () {
config.set({x: 'y'});
config.cache.x.should.equal('y');
config.get('x').should.equal('y');
app.set({x: 'y'});
app.cache.x.should.equal('y');
app.get('x').should.equal('y');
});
it('should set nested properties on the `cache` object.', function () {
config.set('c', {d: 'e'});
config.get('c').d.should.equal('e');
app.set('c', {d: 'e'});
app.get('c').d.should.equal('e');
});
it('should return `this` for chaining', function () {
config.set('a', 'b').should.equal(config);
config
app.set('a', 'b').should.equal(app);
app
.set('aa', 'bb')
.set('bb', 'cc')
.set('cc', 'dd');
config.get('aa').should.equal('bb');
config.get('bb').should.equal('cc');
config.get('cc').should.equal('dd');
app.get('aa').should.equal('bb');
app.get('bb').should.equal('cc');
app.get('cc').should.equal('dd');
});
it('should return undefined when not set', function () {
config.set('a', undefined).should.equal(config);
app.set('a', undefined).should.equal(app);
});

@@ -63,8 +63,8 @@ });

it('should return undefined when no set', function () {
assert(config.get('a') === undefined);
assert(app.get('a') === undefined);
});
it('should otherwise return the value', function () {
config.set('a', 'b');
config.get('a').should.equal('b');
app.set('a', 'b');
app.get('a').should.equal('b');
});

@@ -71,0 +71,0 @@ });

/*!
* storage <https://github.com/jonschlinkert/storage>
* cache-base <https://github.com/jonschlinkert/cache-base>
*

@@ -10,11 +10,10 @@ * Copyright (c) 2014 Jon Schlinkert, contributors.

var assert = require('assert');
var should = require('should');
var Storage = require('..');
var storage = new Storage();
var Cache = require('..');
var app;
describe('storage has', function () {
afterEach(function() {
storage.clear();
describe('app.has()', function () {
beforeEach(function() {
app = new Cache();
});

@@ -24,11 +23,11 @@

it('should return `true` if a deep property is on the cache.', function () {
storage.set('a', {b: 'c'});
storage.has('a.b').should.be.true;
app.set('a', {b: 'c'});
app.has('a.b').should.be.true;
});
it('should return `false` if a deep property is not on the cache.', function () {
storage.set('a', 'b');
storage.has('a.c').should.be.false;
app.set('a', 'b');
app.has('a.c').should.be.false;
});
});
});
/*!
* config-cache <https://github.com/jonschlinkert/config-cache>
* cache-base <https://github.com/jonschlinkert/cache-base>
*

@@ -10,11 +10,10 @@ * Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors.

var assert = require('assert');
var should = require('should');
var Config = require('..');
var config = new Config();
var Cache = require('..');
var app;
describe('config hasOwn', function () {
afterEach(function() {
config.clear();
describe('app.hasOwn()', function () {
beforeEach(function() {
app = new Cache();
});

@@ -24,9 +23,9 @@

it('should return `true` if the property is on the cache.', function () {
config.set('a', 'b');
config.hasOwn('a').should.be.true;
app.set('a', 'b');
app.hasOwn('a').should.be.true;
});
it('should return `false` if the property is not on the cache.', function () {
config.set('a', 'b');
config.hasOwn('b').should.be.false;
app.set('a', 'b');
app.hasOwn('b').should.be.false;
});

@@ -37,13 +36,13 @@ });

it('should return `true` if the property is on the cache.', function () {
config.set('a', 'b');
config.get('a').should.equal('b');
app.set('a', 'b');
app.get('a').should.equal('b');
config.hasOwn('a').should.be.true;
config.hasOwn({}, 'a').should.be.false;
app.hasOwn('a').should.be.true;
app.hasOwn({}, 'a').should.be.false;
});
it('should return `true` if the property is on the given object.', function () {
config.set('a', 'b');
config.hasOwn('a').should.be.true;
config.hasOwn({}, 'a').should.be.false;
app.set('a', 'b');
app.hasOwn('a').should.be.true;
app.hasOwn({}, 'a').should.be.false;
});

@@ -53,12 +52,12 @@

it('should return `false` when the property does not exist on the cache.', function () {
config.set('a', 'b');
config.hasOwn('b').should.be.false;
app.set('a', 'b');
app.hasOwn('b').should.be.false;
});
it('should return `false` when the property does not exist on the given object.', function () {
config.set('a', 'b');
config.hasOwn('a').should.be.true;
config.hasOwn({}, 'a').should.be.false;
app.set('a', 'b');
app.hasOwn('a').should.be.true;
app.hasOwn({}, 'a').should.be.false;
});
});
});
/*!
* storage <https://github.com/jonschlinkert/storage>
* cache-base <https://github.com/jonschlinkert/cache-base>
*

@@ -10,11 +10,10 @@ * Copyright (c) 2014 Jon Schlinkert, contributors.

var assert = require('assert');
var should = require('should');
var Storage = require('..');
var storage = new Storage();
var Cache = require('..');
var app;
describe('storage keys', function () {
afterEach(function() {
storage.clear();
describe('app.keys()', function () {
beforeEach(function() {
app = new Cache();
});

@@ -24,12 +23,12 @@

it('should return the keys from objects on the `cache`.', function () {
storage.set('a', 'b');
storage.keys().should.eql(['a']);
storage.set('c', 'd');
storage.keys().should.eql(['a', 'c']);
app.set('a', 'b');
app.keys().should.eql(['a']);
app.set('c', 'd');
app.keys().should.eql(['a', 'c']);
});
it('should return the keys from the given object', function () {
storage.keys({a: 'a', b: 'b'}).should.eql(['a', 'b']);
app.keys({a: 'a', b: 'b'}).should.eql(['a', 'b']);
});
});
});

@@ -10,36 +10,44 @@ /*!

var assert = require('assert');
var should = require('should');
var Config = require('..');
var config = new Config();
var Cache = require('..');
var app;
describe('config merge', function () {
afterEach(function() {
config.clear();
describe('app.merge()', function () {
beforeEach(function() {
app = new Cache();
});
describe('.merge()', function() {
it('should merge a value onto the `cache`.', function() {
config.merge({a: 'b'});
config.get('a').should.equal('b');
it('should merge the `cache` object with an object.', function() {
app.merge({a: 'b'});
app.get('a').should.equal('b');
});
it('should deep merge a value onto the `cache`.', function() {
config.merge({a: {b: 'b'}});
config.merge({a: {c: 'c'}});
config.get('a').should.eql({b: 'b', c: 'c'});
it('should merge the given object with a key/value pair.', function() {
app.set('a', {b: 'c'});
app.merge('a', {d: 'e'});
app.get('a').should.eql({b: 'c', d: 'e'});
});
it('should merge the `cache` with an object.', function() {
config
it('should merge the `cache` object with a list of values.', function() {
app.merge({a: 'b'}, {c: 'd'});
app.get().should.eql({a: 'b', c: 'd'});
});
it('should merge the `cache` object with an array of values.', function() {
app.merge([{a: 'b'}, {c: 'd'}]);
app.get().should.eql({a: 'b', c: 'd'});
});
it('should merge the `cache` object a mixture of list values and array values.', function() {
app.merge({a: 'b'}, [{c: 'd'}, {e: 'f'}]);
app.get().should.eql({a: 'b', c: 'd', e: 'f'});
});
it('should be chainable.', function() {
app
.merge({x: 'x', y: 'y', z: 'z'})
.merge({a: 'a', b: 'b', c: 'c'});
config.get().should.have.property('a');
config.get().should.have.property('b');
config.get().should.have.property('c');
config.get().should.have.property('x');
config.get().should.have.property('y');
config.get().should.have.property('z');
app.get().should.have.properties('a', 'b', 'c', 'x', 'y', 'z');
});

@@ -50,12 +58,12 @@ });

it('should merge the `cache` with the last value defined.', function() {
config.merge({a: 'B'}, {a: 'C'});
config.get('a').should.equal('C');
app.merge({a: 'B'}, {a: 'C'});
app.get('a').should.equal('C');
});
it('should merge the `cache` with the last value defined.', function() {
config
app
.merge({a: 'B'})
.merge({a: 'C'});
config.get('a').should.equal('C');
app.get('a').should.equal('C');
});

@@ -66,25 +74,25 @@ });

it('should merge that property on the cache.', function() {
config
app
.merge('foo', {x: 'x', y: 'y', z: 'z'})
.merge('bar', {a: 'a', b: 'b', c: 'c'});
config.get('bar').should.have.property('a');
config.get('bar').should.have.property('b');
config.get('bar').should.have.property('c');
config.get('foo').should.have.property('x');
config.get('foo').should.have.property('y');
config.get('foo').should.have.property('z');
app.get('bar').should.have.property('a');
app.get('bar').should.have.property('b');
app.get('bar').should.have.property('c');
app.get('foo').should.have.property('x');
app.get('foo').should.have.property('y');
app.get('foo').should.have.property('z');
});
it('should merge the `cache.data` object.', function() {
config
app
.merge('data', {x: 'x', y: 'y', z: 'z'})
.merge('data', {a: 'a', b: 'b', c: 'c'});
config.get('data').should.have.property('a');
config.get('data').should.have.property('b');
config.get('data').should.have.property('c');
config.get('data').should.have.property('x');
config.get('data').should.have.property('y');
config.get('data').should.have.property('z');
app.get('data').should.have.property('a');
app.get('data').should.have.property('b');
app.get('data').should.have.property('c');
app.get('data').should.have.property('x');
app.get('data').should.have.property('y');
app.get('data').should.have.property('z');
});

@@ -95,11 +103,11 @@ });

it('should merge the cache with a key-value pair.', function () {
config.merge('a', {b: 'c'});
config.hasOwn('a').should.be.true;
config.cache.should.have.property('a', {b: 'c'});
app.merge('a', {b: 'c'});
app.hasOwn('a').should.be.true;
app.cache.should.have.property('a', {b: 'c'});
});
it('should merge the cache with an object.', function () {
config.merge({a: 'b', c: 'd'});
config.hasOwn('a').should.be.true;
config.hasOwn('c').should.be.true;
app.merge({a: 'b', c: 'd'});
app.hasOwn('a').should.be.true;
app.hasOwn('c').should.be.true;
});

@@ -110,37 +118,37 @@ });

// it('should merge that property on the cache.', function() {
// config
// app
// .merge('foo', {xyz: {x: 'x', y: 'y', z: 'z'}})
// .merge('bar', {xyz: {a: 'a', b: 'b', c: 'c'}});
// config.get('bar.xyz').should.have.property('a');
// config.get('bar.xyz').should.have.property('b');
// config.get('bar.xyz').should.have.property('c');
// config.get('foo.xyz').should.have.property('x');
// config.get('foo.xyz').should.have.property('y');
// config.get('foo.xyz').should.have.property('z');
// app.get('bar.xyz').should.have.property('a');
// app.get('bar.xyz').should.have.property('b');
// app.get('bar.xyz').should.have.property('c');
// app.get('foo.xyz').should.have.property('x');
// app.get('foo.xyz').should.have.property('y');
// app.get('foo.xyz').should.have.property('z');
// config.cache.bar.should.have.property('xyz');
// config.cache.bar.should.have.property('xyz');
// config.cache.bar.should.have.property('xyz');
// config.cache.foo.should.have.property('xyz');
// config.cache.foo.should.have.property('xyz');
// config.cache.foo.should.have.property('xyz');
// app.cache.bar.should.have.property('xyz');
// app.cache.bar.should.have.property('xyz');
// app.cache.bar.should.have.property('xyz');
// app.cache.foo.should.have.property('xyz');
// app.cache.foo.should.have.property('xyz');
// app.cache.foo.should.have.property('xyz');
// });
// it('should merge deep properties.', function() {
// config.merge('a.b.c.d.xyz', {x: 'x', y: 'y', z: 'z'})
// app.merge('a.b.c.d.xyz', {x: 'x', y: 'y', z: 'z'})
// config.get('a.b.c.d.xyz').should.have.property('x');
// config.get('a.b.c.d.xyz').should.have.property('y');
// config.get('a.b.c.d.xyz').should.have.property('z');
// app.get('a.b.c.d.xyz').should.have.property('x');
// app.get('a.b.c.d.xyz').should.have.property('y');
// app.get('a.b.c.d.xyz').should.have.property('z');
// config.cache.a.b.c.d.should.have.property('xyz');
// config.cache.a.b.c.d.should.have.property('xyz');
// config.cache.a.b.c.d.should.have.property('xyz');
// app.cache.a.b.c.d.should.have.property('xyz');
// app.cache.a.b.c.d.should.have.property('xyz');
// app.cache.a.b.c.d.should.have.property('xyz');
// config.cache.a.b.c.d.xyz.should.have.property('x');
// config.cache.a.b.c.d.xyz.should.have.property('x');
// config.cache.a.b.c.d.xyz.should.have.property('x');
// app.cache.a.b.c.d.xyz.should.have.property('x');
// app.cache.a.b.c.d.xyz.should.have.property('x');
// app.cache.a.b.c.d.xyz.should.have.property('x');
// });
// });
});
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