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.4.0 to 0.6.0

LICENSE

67

index.js
'use strict';
var util = require('util');
var chalk = require('chalk');
var typeOf = require('kind-of');
var Options = require('option-cache');
var omit = require('object.omit');
var pick = require('object.pick');
var get = require('get-value');

@@ -78,5 +75,4 @@ var _ = require('lodash');

Cache.prototype.get = function (key) {
if (!key) {
return _.cloneDeep(this.cache);
}
if (!key) return this.clone();
if (key.indexOf('.') !== -1) {

@@ -92,4 +88,2 @@ return get(this.cache, key, true);

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

@@ -115,4 +109,2 @@ * app.exists('author.name');

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

@@ -135,8 +127,8 @@ * app

var o = this.get(val) || {};
o = _.extend.apply(_, [o].concat(rest));
o = extend(o, rest);
this.cache[val] = o;
return this;
} else {
extend(this.cache, args);
}
_.extend.apply(_, [this.cache].concat(args));
return this;

@@ -148,4 +140,2 @@ };

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

@@ -168,8 +158,8 @@ * app.merge({a: {one: 'one'}}, {a: {two: 'two'}});

var o = this.get(val) || {};
o = _.merge.apply(_, [o].concat(rest));
o = merge(o, rest);
this.cache[val] = o;
return this;
} else {
merge(this.cache, args);
}
_.merge.apply(_, [this.cache].concat(args));
return this;

@@ -179,12 +169,15 @@ };

/**
* Delete a property or array of properties from the cache then
* re-save the cache.
* Extend the cache with only the specified values from the given
* object.
*
* ```js
* app.pick('foo');
* // or
* app.pick(['foo', 'bar']);
* var obj = {a: 'a', b: 'b', c: 'c'};
* app.pick(obj, 'a');
* //=> {a: 'a'}
*
* app.pick(obj, ['a', 'b']);
* //=> {a: 'a', b: 'b'}
* ```
*
* @param {String|Array} `key` The key(s) to pick from the cache
* @param {String|Array} `key` The key(s) to pick from the object and extend onto `app.cache`
* @api public

@@ -194,8 +187,7 @@ */

Cache.prototype.pick = function(o, keys) {
this.extend(pick(o, keys));
this.extend(_.pick(o, keys));
};
/**
* Delete a property or array of properties from the cache then
* re-save the cache.
* Omit a property or array of properties from the cache
*

@@ -213,3 +205,3 @@ * ```js

Cache.prototype.omit = function(keys) {
this.cache = omit(this.cache, keys);
this.cache = _.omit(this.cache, keys);
};

@@ -359,2 +351,19 @@

}
};
};
/**
* Utils
*/
function extend(o, objects) {
return _.extend.apply(_, [o].concat(objects));
}
function merge(o, objects) {
return _.merge.apply(_, [o].concat(objects));
}
function union () {
return [].concat.apply([], arguments);
}
{
"name": "cache-base",
"description": "Generic object cache for node.js/javascript projects.",
"version": "0.4.0",
"version": "0.6.0",
"homepage": "https://github.com/jonschlinkert/cache-base",

@@ -17,8 +17,6 @@ "author": {

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

@@ -32,18 +30,14 @@ "index.js"

"scripts": {
"test": "mocha",
"lint": "deps -e test"
"test": "mocha"
},
"dependencies": {
"get-value": "^1.1.1",
"kind-of": "^1.1.0",
"lodash": "^3.5.0",
"option-cache": "^1.2.2"
},
"devDependencies": {
"mocha": "*",
"should": "^4.0.4"
"should": "^5.1.0"
},
"dependencies": {
"chalk": "^0.5.1",
"get-value": "^1.0.2",
"kind-of": "^1.1.0",
"lodash": "^3.2.0",
"object.omit": "^0.2.1",
"object.pick": "^1.1.1",
"option-cache": "^1.1.0"
},
"keywords": [

@@ -50,0 +44,0 @@ "config",

@@ -1,2 +0,2 @@

# cache-base [![NPM version](https://badge.fury.io/js/cache-base.svg)](http://badge.fury.io/js/cache-base)
# cache-base [![NPM version](https://badge.fury.io/js/cache-base.svg)](http://badge.fury.io/js/cache-base) [![Build Status](https://travis-ci.org/jonschlinkert/cache-base.svg)](https://travis-ci.org/jonschlinkert/cache-base)

@@ -48,3 +48,3 @@ > Generic object cache for node.js/javascript projects.

## API
### [Cache](index.js#L31)
### [Cache](./index.js#L28)

@@ -59,3 +59,3 @@ Create a new instance of `Cache`

### [.set](index.js#L54)
### [.set](./index.js#L51)

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

### [.get](index.js#L77)
### [.get](./index.js#L74)

@@ -88,3 +88,3 @@ Return the stored value of `key`. If `key` is not defined, the `cache` is returned.

### [.exists](index.js#L103)
### [.exists](./index.js#L97)

@@ -96,4 +96,2 @@ Return `true` if the element exists. Dot notation may be used for nested properties.

**Example**
```js

@@ -104,3 +102,3 @@ app.exists('author.name');

### [.extend](index.js#L126)
### [.extend](./index.js#L119)

@@ -111,4 +109,2 @@ Extend the `cache` with the given object.

**Example**
```js

@@ -120,3 +116,3 @@ app

### [.merge](index.js#L157)
### [.merge](./index.js#L148)

@@ -127,4 +123,2 @@ Deep merge an object onto the `cache`.

**Example**
```js

@@ -136,17 +130,20 @@ app.merge({a: {one: 'one'}}, {a: {two: 'two'}});

### [.pick](index.js#L186)
### [.pick](./index.js#L180)
Delete a property or array of properties from the cache then re-save the cache.
Extend the cache with only the specified values from the given object.
* `key` **{String|Array}**: The key(s) to pick from the cache
* `key` **{String|Array}**: The key(s) to pick from the object and extend onto `app.cache`
```js
app.pick('foo');
// or
app.pick(['foo', 'bar']);
var obj = {a: 'a', b: 'b', c: 'c'};
app.pick(obj, 'a');
//=> {a: 'a'}
app.pick(obj, ['a', 'b']);
//=> {a: 'a', b: 'b'}
```
### [.omit](index.js#L204)
### [.omit](./index.js#L197)
Delete a property or array of properties from the cache then re-save the cache.
Omit a property or array of properties from the cache

@@ -161,3 +158,3 @@ * `key` **{String|Array}**: The key(s) to omit from the cache

### [.forOwn](index.js#L220)
### [.forOwn](./index.js#L213)

@@ -173,3 +170,3 @@ Return the keys on `obj` or `this.cache`.

### [.keys](index.js#L240)
### [.keys](./index.js#L233)

@@ -185,3 +182,3 @@ Return the keys on `obj` or `this.cache`.

### [.functions](index.js#L258)
### [.functions](./index.js#L251)

@@ -198,3 +195,3 @@ Return an object of only the properties on `this.cache` or the given `obj` that have function values.

### [.has](index.js#L284)
### [.has](./index.js#L277)

@@ -210,3 +207,3 @@ Return true if a deep property is on the given object or `this.cache`.

### [.hasOwn](index.js#L307)
### [.hasOwn](./index.js#L300)

@@ -225,3 +222,3 @@ Return true if `key` is an own, enumerable property of `this.cache` or the given `obj`.

### [.clone](index.js#L326)
### [.clone](./index.js#L319)

@@ -237,3 +234,3 @@ Clone the given `obj` or `cache`.

### [.clear](index.js#L344)
### [.clear](./index.js#L337)

@@ -251,2 +248,20 @@ Remove `key` from the cache, or if no value is specified the entire cache is reset.

## Related
* [option-cache](https://github.com/jonschlinkert/option-cache): Simple API for managing options in JavaScript applications.
* [config-cache](https://github.com/jonschlinkert/config-cache): General purpose JavaScript object storage methods.
* [engine-cache](https://github.com/jonschlinkert/engine-cache): express.js inspired template-engine manager.
* [loader-cache](https://github.com/jonschlinkert/loader-cache): Register loader functions that dynamically read, parse or otherwise transform file contents when the name of the loader matches a file extension. You can also compose loaders from other loaders.
* [parser-cache](https://github.com/jonschlinkert/parser-cache): Cache and load parsers, similiar to consolidate.js engines.
* [helper-cache](https://github.com/jonschlinkert/helper-cache): Easily register and get helper functions to be passed to any template engine or node.js application. Methods for both sync and async helpers.
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/cache-base/issues)
## Running tests
Install dev dependencies.
```bash
npm i -d && npm test
```
## Author

@@ -265,2 +280,3 @@

_This file was generated by [verb](https://github.com/assemble/verb) on February 14, 2015._
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 11, 2015._
<!-- deps:mocha -->
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