cache-base
Advanced tools
Comparing version 1.0.0 to 1.0.1
42
index.js
'use strict'; | ||
var utils = require('./utils'); | ||
var isObject = require('isobject'); | ||
var Emitter = require('component-emitter'); | ||
var visit = require('collection-visit'); | ||
var toPath = require('to-object-path'); | ||
var union = require('union-value'); | ||
var del = require('unset-value'); | ||
var get = require('get-value'); | ||
var has = require('has-value'); | ||
var set = require('set-value'); | ||
@@ -48,3 +56,3 @@ /** | ||
utils.Emitter(Cache.prototype); | ||
Emitter(Cache.prototype); | ||
@@ -79,8 +87,8 @@ /** | ||
if (Array.isArray(key) && arguments.length === 2) { | ||
key = utils.toPath(key); | ||
key = toPath(key); | ||
} | ||
if (utils.isObject(key) || Array.isArray(key)) { | ||
if (isObject(key) || Array.isArray(key)) { | ||
this.visit('set', key); | ||
} else { | ||
utils.set(prop ? this[prop] : this, key, val); | ||
set(prop ? this[prop] : this, key, val); | ||
this.emit('set', key, val); | ||
@@ -110,6 +118,6 @@ } | ||
if (Array.isArray(key) && arguments.length === 2) { | ||
key = utils.toPath(key); | ||
key = toPath(key); | ||
} | ||
var ctx = prop ? this[prop] : this; | ||
utils.union(ctx, key, utils.arrayify(val)); | ||
union(ctx, key, arrayify(val)); | ||
this.emit('union', val); | ||
@@ -140,6 +148,6 @@ return this; | ||
Cache.prototype.get = function(key) { | ||
key = utils.toPath(arguments); | ||
key = toPath(arguments); | ||
var ctx = prop ? this[prop] : this; | ||
var val = utils.get(ctx, key); | ||
var val = get(ctx, key); | ||
@@ -168,6 +176,6 @@ this.emit('get', key, val); | ||
Cache.prototype.has = function(key) { | ||
key = utils.toPath(arguments); | ||
key = toPath(arguments); | ||
var ctx = prop ? this[prop] : this; | ||
var val = utils.get(ctx, key); | ||
var val = get(ctx, key); | ||
@@ -200,3 +208,3 @@ var has = typeof val !== 'undefined'; | ||
} else { | ||
utils.del(prop ? this[prop] : this, key); | ||
del(prop ? this[prop] : this, key); | ||
this.emit('del', key); | ||
@@ -234,3 +242,3 @@ } | ||
Cache.prototype.visit = function(method, val) { | ||
utils.visit(this, method, val); | ||
visit(this, method, val); | ||
return this; | ||
@@ -243,2 +251,10 @@ }; | ||
/** | ||
* Cast val to an array | ||
*/ | ||
function arrayify(val) { | ||
return val ? (Array.isArray(val) ? val : [val]) : []; | ||
} | ||
/** | ||
* Expose `Cache` | ||
@@ -245,0 +261,0 @@ */ |
{ | ||
"name": "cache-base", | ||
"description": "Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects.", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"homepage": "https://github.com/jonschlinkert/cache-base", | ||
"author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"contributors": [ | ||
"<wtgtybhertgeghgtwtg@gmail.com> (https://github.com/wtgtybhertgeghgtwtg)", | ||
"Jon Schlinkert <jon.schlinkert@sellside.com> (http://twitter.com/jonschlinkert)" | ||
"Jon Schlinkert (http://twitter.com/jonschlinkert)", | ||
"(https://github.com/wtgtybhertgeghgtwtg)" | ||
], | ||
@@ -17,4 +17,3 @@ "repository": "jonschlinkert/cache-base", | ||
"files": [ | ||
"index.js", | ||
"utils.js" | ||
"index.js" | ||
], | ||
@@ -29,16 +28,15 @@ "main": "index.js", | ||
"dependencies": { | ||
"collection-visit": "^0.2.1", | ||
"collection-visit": "^1.0.0", | ||
"component-emitter": "^1.2.1", | ||
"get-value": "^2.0.5", | ||
"has-value": "^0.3.1", | ||
"isobject": "^3.0.0", | ||
"lazy-cache": "^2.0.1", | ||
"set-value": "^0.4.2", | ||
"get-value": "^2.0.6", | ||
"has-value": "^1.0.0", | ||
"isobject": "^3.0.1", | ||
"set-value": "^2.0.0", | ||
"to-object-path": "^0.3.0", | ||
"union-value": "^0.2.3", | ||
"unset-value": "^0.1.1" | ||
"union-value": "^1.0.0", | ||
"unset-value": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"gulp-format-md": "^0.1.8", | ||
"mocha": "^2.4.5" | ||
"gulp-format-md": "^1.0.0", | ||
"mocha": "^3.4.2" | ||
}, | ||
@@ -45,0 +43,0 @@ "keywords": [ |
@@ -1,2 +0,2 @@ | ||
# cache-base [![NPM version](https://img.shields.io/npm/v/cache-base.svg?style=flat)](https://www.npmjs.com/package/cache-base) [![NPM monthly downloads](https://img.shields.io/npm/dm/cache-base.svg?style=flat)](https://npmjs.org/package/cache-base) [![NPM total downloads](https://img.shields.io/npm/dt/cache-base.svg?style=flat)](https://npmjs.org/package/cache-base) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/cache-base.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/cache-base) | ||
# cache-base [![NPM version](https://img.shields.io/npm/v/cache-base.svg?style=flat)](https://www.npmjs.com/package/cache-base) [![NPM monthly downloads](https://img.shields.io/npm/dm/cache-base.svg?style=flat)](https://npmjs.org/package/cache-base) [![NPM total downloads](https://img.shields.io/npm/dt/cache-base.svg?style=flat)](https://npmjs.org/package/cache-base) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/cache-base.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/cache-base) | ||
@@ -66,3 +66,3 @@ > Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects. | ||
### [namespace](index.js#L21) | ||
### [namespace](index.js#L29) | ||
@@ -86,3 +86,3 @@ Create a `Cache` constructor that when instantiated will store values on the given `prop`. | ||
### [Cache](index.js#L35) | ||
### [Cache](index.js#L43) | ||
@@ -101,3 +101,3 @@ Create a new `Cache`. Internally the `Cache` constructor is created using the `namespace` function, with `cache` defined as the storage object. | ||
### [.set](index.js#L76) | ||
### [.set](index.js#L84) | ||
@@ -132,3 +132,3 @@ Assign `value` to `key`. Also emits `set` with the key and value. | ||
### [.union](index.js#L106) | ||
### [.union](index.js#L114) | ||
@@ -152,3 +152,3 @@ Union `array` to `key`. Also emits `set` with the key and value. | ||
### [.get](index.js#L136) | ||
### [.get](index.js#L144) | ||
@@ -177,3 +177,3 @@ Return the value of `key`. Dot notation may be used to get [nested property values](https://github.com/jonschlinkert/get-value). | ||
### [.has](index.js#L163) | ||
### [.has](index.js#L171) | ||
@@ -199,3 +199,3 @@ Return true if app has a stored value for `key`, false only if value is `undefined`. | ||
### [.del](index.js#L191) | ||
### [.del](index.js#L199) | ||
@@ -223,3 +223,3 @@ Delete one or more properties from the instance. | ||
### [.clear](index.js#L210) | ||
### [.clear](index.js#L218) | ||
@@ -234,3 +234,3 @@ Reset the entire cache to an empty object. | ||
### [.visit](index.js#L227) | ||
### [.visit](index.js#L235) | ||
@@ -265,3 +265,3 @@ Visit `method` over the properties in the given object, or map | ||
| --- | --- | | ||
| 51 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 54 | [jonschlinkert](https://github.com/jonschlinkert) | | ||
| 2 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) | | ||
@@ -301,2 +301,2 @@ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.4.2, on February 25, 2017._ | ||
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on July 22, 2017._ |
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
9
1
16440
4
229
+ Addedassign-symbols@1.0.0(transitive)
+ Addedcollection-visit@1.0.0(transitive)
+ Addedextend-shallow@3.0.2(transitive)
+ Addedhas-value@1.0.0(transitive)
+ Addedhas-values@1.0.0(transitive)
+ Addedis-extendable@1.0.1(transitive)
+ Addedis-number@3.0.0(transitive)
+ Addedkind-of@4.0.0(transitive)
+ Addedmap-visit@1.0.0(transitive)
+ Addedobject-visit@1.0.1(transitive)
+ Addedset-value@2.0.1(transitive)
+ Addedsplit-string@3.1.0(transitive)
+ Addedunion-value@1.0.1(transitive)
+ Addedunset-value@1.0.0(transitive)
- Removedlazy-cache@^2.0.1
- Removedcollection-visit@0.2.3(transitive)
- Removedlazy-cache@2.0.2(transitive)
- Removedmap-visit@0.1.5(transitive)
- Removedobject-visit@0.3.4(transitive)
- Removedset-getter@0.1.1(transitive)
- Removedset-value@0.4.3(transitive)
- Removedunion-value@0.2.4(transitive)
- Removedunset-value@0.1.2(transitive)
Updatedcollection-visit@^1.0.0
Updatedget-value@^2.0.6
Updatedhas-value@^1.0.0
Updatedisobject@^3.0.1
Updatedset-value@^2.0.0
Updatedunion-value@^1.0.0
Updatedunset-value@^1.0.0