[Pkg-javascript-commits] [node-cache-base] 01/06: Import Upstream version 0.8.4
Sruthi Chandran
srud-guest at moszumanska.debian.org
Mon Oct 31 11:19:26 UTC 2016
This is an automated email from the git hooks/post-receive script.
srud-guest pushed a commit to branch master
in repository node-cache-base.
commit cccb71473f3187687ac021a936ab8e952b1bc82c
Author: Sruthi <srud at disroot.org>
Date: Mon Oct 31 16:33:22 2016 +0530
Import Upstream version 0.8.4
---
.editorconfig | 22 +++
.eslintrc.json | 275 ++++++++++++++++++++++++++++++
.gitattributes | 10 ++
.gitignore | 11 ++
.travis.yml | 12 ++
.verb.md | 54 ++++++
LICENSE | 21 +++
README.md | 284 +++++++++++++++++++++++++++++++
index.js | 245 +++++++++++++++++++++++++++
package.json | 79 +++++++++
test/fixtures/a.yml | 1 +
test/fixtures/data/alert.json | 7 +
test/fixtures/data/data.json | 3 +
test/fixtures/data/test.json | 4 +
test/fixtures/namespace/a.yml | 1 +
test/fixtures/namespace/b.yml | 1 +
test/fixtures/namespace/c.json | 3 +
test/test.js | 369 +++++++++++++++++++++++++++++++++++++++++
utils.js | 38 +++++
19 files changed, 1440 insertions(+)
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..408d870
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,22 @@
+# http://editorconfig.org
+root = true
+
+[*]
+indent_style = space
+end_of_line = lf
+charset = utf-8
+indent_size = 2
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.md]
+trim_trailing_whitespace = false
+insert_final_newline = false
+
+[**/{actual,fixtures,expected}/**]
+trim_trailing_whitespace = false
+insert_final_newline = false
+
+[**/templates/**]
+trim_trailing_whitespace = false
+insert_final_newline = false
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 0000000..5b78706
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,275 @@
+{
+ "ecmaFeatures": {
+ "modules": true,
+ "experimentalObjectRestSpread": true
+ },
+ "env": {
+ "browser": false,
+ "es6": true,
+ "node": true,
+ "mocha": true
+ },
+ "globals": {
+ "document": false,
+ "navigator": false,
+ "window": false
+ },
+ "rules": {
+ "accessor-pairs": 2,
+ "arrow-spacing": [
+ 2,
+ {
+ "before": true,
+ "after": true
+ }
+ ],
+ "block-spacing": [
+ 2,
+ "always"
+ ],
+ "brace-style": [
+ 2,
+ "1tbs",
+ {
+ "allowSingleLine": true
+ }
+ ],
+ "comma-dangle": [
+ 2,
+ "never"
+ ],
+ "comma-spacing": [
+ 2,
+ {
+ "before": false,
+ "after": true
+ }
+ ],
+ "comma-style": [
+ 2,
+ "last"
+ ],
+ "constructor-super": 2,
+ "curly": [
+ 2,
+ "multi-line"
+ ],
+ "dot-location": [
+ 2,
+ "property"
+ ],
+ "eol-last": 2,
+ "eqeqeq": [
+ 2,
+ "allow-null"
+ ],
+ "generator-star-spacing": [
+ 2,
+ {
+ "before": true,
+ "after": true
+ }
+ ],
+ "handle-callback-err": [
+ 2,
+ "^(err|error)$"
+ ],
+ "indent": [
+ 2,
+ 2,
+ {
+ "SwitchCase": 1
+ }
+ ],
+ "key-spacing": [
+ 2,
+ {
+ "beforeColon": false,
+ "afterColon": true
+ }
+ ],
+ "keyword-spacing": [
+ 2,
+ {
+ "before": true,
+ "after": true
+ }
+ ],
+ "new-cap": [
+ 2,
+ {
+ "newIsCap": true,
+ "capIsNew": false
+ }
+ ],
+ "new-parens": 2,
+ "no-array-constructor": 2,
+ "no-caller": 2,
+ "no-class-assign": 2,
+ "no-cond-assign": 2,
+ "no-const-assign": 2,
+ "no-control-regex": 2,
+ "no-debugger": 2,
+ "no-delete-var": 2,
+ "no-dupe-args": 2,
+ "no-dupe-class-members": 2,
+ "no-dupe-keys": 2,
+ "no-duplicate-case": 2,
+ "no-empty-character-class": 2,
+ "no-eval": 2,
+ "no-ex-assign": 2,
+ "no-extend-native": 2,
+ "no-extra-bind": 2,
+ "no-extra-boolean-cast": 2,
+ "no-extra-parens": [
+ 2,
+ "functions"
+ ],
+ "no-fallthrough": 2,
+ "no-floating-decimal": 2,
+ "no-func-assign": 2,
+ "no-implied-eval": 2,
+ "no-inner-declarations": [
+ 2,
+ "functions"
+ ],
+ "no-invalid-regexp": 2,
+ "no-irregular-whitespace": 2,
+ "no-iterator": 2,
+ "no-label-var": 2,
+ "no-labels": 2,
+ "no-lone-blocks": 2,
+ "no-mixed-spaces-and-tabs": 2,
+ "no-multi-spaces": 2,
+ "no-multi-str": 2,
+ "no-multiple-empty-lines": [
+ 2,
+ {
+ "max": 1
+ }
+ ],
+ "no-native-reassign": 0,
+ "no-negated-in-lhs": 2,
+ "no-new": 2,
+ "no-new-func": 2,
+ "no-new-object": 2,
+ "no-new-require": 2,
+ "no-new-wrappers": 2,
+ "no-obj-calls": 2,
+ "no-octal": 2,
+ "no-octal-escape": 2,
+ "no-proto": 0,
+ "no-redeclare": 2,
+ "no-regex-spaces": 2,
+ "no-return-assign": 2,
+ "no-self-compare": 2,
+ "no-sequences": 2,
+ "no-shadow-restricted-names": 2,
+ "no-spaced-func": 2,
+ "no-sparse-arrays": 2,
+ "no-this-before-super": 2,
+ "no-throw-literal": 2,
+ "no-trailing-spaces": 0,
+ "no-undef": 2,
+ "no-undef-init": 2,
+ "no-unexpected-multiline": 2,
+ "no-unneeded-ternary": [
+ 2,
+ {
+ "defaultAssignment": false
+ }
+ ],
+ "no-unreachable": 2,
+ "no-unused-vars": [
+ 2,
+ {
+ "vars": "all",
+ "args": "none"
+ }
+ ],
+ "no-useless-call": 0,
+ "no-with": 2,
+ "one-var": [
+ 0,
+ {
+ "initialized": "never"
+ }
+ ],
+ "operator-linebreak": [
+ 0,
+ "after",
+ {
+ "overrides": {
+ "?": "before",
+ ":": "before"
+ }
+ }
+ ],
+ "padded-blocks": [
+ 0,
+ "never"
+ ],
+ "quotes": [
+ 2,
+ "single",
+ "avoid-escape"
+ ],
+ "radix": 2,
+ "semi": [
+ 2,
+ "always"
+ ],
+ "semi-spacing": [
+ 2,
+ {
+ "before": false,
+ "after": true
+ }
+ ],
+ "space-before-blocks": [
+ 2,
+ "always"
+ ],
+ "space-before-function-paren": [
+ 2,
+ "never"
+ ],
+ "space-in-parens": [
+ 2,
+ "never"
+ ],
+ "space-infix-ops": 2,
+ "space-unary-ops": [
+ 2,
+ {
+ "words": true,
+ "nonwords": false
+ }
+ ],
+ "spaced-comment": [
+ 0,
+ "always",
+ {
+ "markers": [
+ "global",
+ "globals",
+ "eslint",
+ "eslint-disable",
+ "*package",
+ "!",
+ ","
+ ]
+ }
+ ],
+ "use-isnan": 2,
+ "valid-typeof": 2,
+ "wrap-iife": [
+ 2,
+ "any"
+ ],
+ "yoda": [
+ 2,
+ "never"
+ ]
+ }
+}
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..4a3f1d3
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,10 @@
+# Enforce Unix newlines
+* text eol=lf
+
+# binaries
+*.ai binary
+*.psd binary
+*.jpg binary
+*.gif binary
+*.png binary
+*.jpeg binary
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..9e685a4
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,11 @@
+*.DS_Store
+*.sublime-*
+_gh_pages
+bower_components
+node_modules
+npm-debug.log
+temp
+test/actual
+tmp
+TODO.md
+vendor
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..cb1d261
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,12 @@
+sudo: false
+language: node_js
+node_js:
+ - '5'
+ - '4'
+ - '0.12'
+ - '0.10'
+matrix:
+ fast_finish: true
+ allow_failures:
+ - node_js: '0.10'
+ - node_js: '0.12'
diff --git a/.verb.md b/.verb.md
new file mode 100644
index 0000000..5bd2017
--- /dev/null
+++ b/.verb.md
@@ -0,0 +1,54 @@
+## Usage
+
+```js
+var Cache = require('{%= name %}');
+
+// instantiate
+var app = new Cache();
+
+// set values
+app.set('a', 'b');
+app.set('c.d', 'e');
+
+// get values
+app.get('a');
+//=> 'b'
+app.get('c');
+//=> {d: 'e'}
+
+console.log(app.cache);
+//=> {a: 'b'}
+```
+
+**Inherit**
+
+```js
+var util = require('util');
+var Cache = require('{%= name %}');
+
+function MyApp() {
+ Cache.call(this);
+}
+util.inherits(MyApp, Cache);
+
+var app = new MyApp();
+app.set('a', 'b');
+app.get('a');
+//=> 'b'
+```
+
+**Namespace**
+
+Define a custom property for storing values.
+
+```js
+var Cache = require('{%= name %}').namespace('data');
+var app = new Cache();
+app.set('a', 'b');
+console.log(app.data);
+//=> {a: 'b'}
+```
+
+## API
+
+{%= apidocs("index.js") %}
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..39245ac
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2014-2016, Jon Schlinkert.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..94d7811
--- /dev/null
+++ b/README.md
@@ -0,0 +1,284 @@
+# cache-base [](https://www.npmjs.com/package/cache-base) [](https://npmjs.org/package/cache-base) [](https://travis-ci.org/jonschlinkert/cache-base)
+
+Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects.
+
+## Install
+
+Install with [npm](https://www.npmjs.com/):
+
+```sh
+$ npm install cache-base --save
+```
+
+## Usage
+
+```js
+var Cache = require('cache-base');
+
+// instantiate
+var app = new Cache();
+
+// set values
+app.set('a', 'b');
+app.set('c.d', 'e');
+
+// get values
+app.get('a');
+//=> 'b'
+app.get('c');
+//=> {d: 'e'}
+
+console.log(app.cache);
+//=> {a: 'b'}
+```
+
+**Inherit**
+
+```js
+var util = require('util');
+var Cache = require('cache-base');
+
+function MyApp() {
+ Cache.call(this);
+}
+util.inherits(MyApp, Cache);
+
+var app = new MyApp();
+app.set('a', 'b');
+app.get('a');
+//=> 'b'
+```
+
+**Namespace**
+
+Define a custom property for storing values.
+
+```js
+var Cache = require('cache-base').namespace('data');
+var app = new Cache();
+app.set('a', 'b');
+console.log(app.data);
+//=> {a: 'b'}
+```
+
+## API
+
+### [namespace](index.js#L21)
+
+Create a `Cache` constructor that when instantiated will store values on the given `prop`.
+
+**Params**
+
+* `prop` **{String}**: The property name to use for storing values.
+* `returns` **{Function}**: Returns a custom `Cache` constructor
+
+**Example**
+
+```js
+var Cache = require('cache-base').namespace('data');
+var cache = new Cache();
+
+cache.set('foo', 'bar');
+//=> {data: {foo: 'bar'}}
+```
+
+### [Cache](index.js#L35)
+
+Create a new `Cache`. Internally the `Cache` constructor is created using the `namespace` function, with `cache` defined as the storage object.
+
+**Params**
+
+* `cache` **{Object}**: Optionally pass an object to initialize with.
+
+**Example**
+
+```js
+var app = new Cache();
+```
+
+### [.set](index.js#L76)
+
+Assign `value` to `key`. Also emits `set` with the key and value.
+
+**Params**
+
+* `key` **{String}**
+* `value` **{any}**
+* `returns` **{Object}**: Returns the instance for chaining.
+
+**Events**
+
+* `emits`: `set` with `key` and `value` as arguments.
+
+**Example**
+
+```js
+app.on('set', function(key, val) {
+ // do something when `set` is emitted
+});
+
+app.set(key, value);
+
+// also takes an object or array
+app.set({name: 'Halle'});
+app.set([{foo: 'bar'}, {baz: 'quux'}]);
+console.log(app);
+//=> {name: 'Halle', foo: 'bar', baz: 'quux'}
+```
+
+### [.union](index.js#L106)
+
+Union `array` to `key`. Also emits `set` with the key and value.
+
+**Params**
+
+* `key` **{String}**
+* `value` **{any}**
+* `returns` **{Object}**: Returns the instance for chaining.
+
+**Example**
+
+```js
+app.union('a.b', ['foo']);
+app.union('a.b', ['bar']);
+console.log(app.get('a'));
+//=> {b: ['foo', 'bar']}
+```
+
+### [.get](index.js#L136)
+
+Return the value of `key`. Dot notation may be used to get [nested property values][get-value].
+
+**Params**
+
+* `key` **{String}**: The name of the property to get. Dot-notation may be used.
+* `returns` **{any}**: Returns the value of `key`
+
+**Events**
+
+* `emits`: `get` with `key` and `value` as arguments.
+
+**Example**
+
+```js
+app.set('a.b.c', 'd');
+app.get('a.b');
+//=> {c: 'd'}
+
+app.get(['a', 'b']);
+//=> {c: 'd'}
+```
+
+### [.has](index.js#L163)
+
+Return true if app has a stored value for `key`, false only if value is `undefined`.
+
+**Params**
+
+* `key` **{String}**
+* `returns` **{Boolean}**
+
+**Events**
+
+* `emits`: `has` with `key` and true or false as arguments.
+
+**Example**
+
+```js
+app.set('foo', 'bar');
+app.has('foo');
+//=> true
+```
+
+### [.del](index.js#L191)
+
+Delete one or more properties from the instance.
+
+**Params**
+
+* `key` **{String|Array}**: Property name or array of property names.
+* `returns` **{Object}**: Returns the instance for chaining.
+
+**Events**
+
+* `emits`: `del` with the `key` as the only argument.
+
+**Example**
+
+```js
+app.del(); // delete all
+// or
+app.del('foo');
+// or
+app.del(['foo', 'bar']);
+```
+
+### [.clear](index.js#L210)
+
+Reset the entire cache to an empty object.
+
+**Example**
+
+```js
+app.clear();
+```
+
+### [.visit](index.js#L227)
+
+Visit `method` over the properties in the given object, or map
+visit over the object-elements in an array.
+
+**Params**
+
+* `method` **{String}**: The name of the `base` method to call.
+* `val` **{Object|Array}**: The object or array to iterate over.
+* `returns` **{Object}**: Returns the instance for chaining.
+
+## Related projects
+
+You might also be interested in these projects:
+
+* [base-methods](https://www.npmjs.com/package/base-methods): base-methods is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://www.npmjs.com/package/base-methods) | [homepage](https://github.com/jonschlinkert/base-methods)
+* [get-value](https://www.npmjs.com/package/get-value): Use property paths (`a.b.c`) to get a nested value from an object. | [homepage](https://github.com/jonschlinkert/get-value)
+* [has-value](https://www.npmjs.com/package/has-value): Returns true if a value exists, false if empty. Works with deeply nested values using… [more](https://www.npmjs.com/package/has-value) | [homepage](https://github.com/jonschlinkert/has-value)
+* [option-cache](https://www.npmjs.com/package/option-cache): Simple API for managing options in JavaScript applications. | [homepage](https://github.com/jonschlinkert/option-cache)
+* [set-value](https://www.npmjs.com/package/set-value): Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths. | [homepage](https://github.com/jonschlinkert/set-value)
+* [unset-value](https://www.npmjs.com/package/unset-value): Delete nested properties from an object using dot notation. | [homepage](https://github.com/jonschlinkert/unset-value)
+
+## Contributing
+
+This document was generated by [verb](https://github.com/verbose/verb), please don't edit directly. Any changes to the readme must be made in [.verb.md](.verb.md). See [Building Docs](#building-docs).
+
+Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/cache-base/issues/new).
+
+## Building docs
+
+Generate readme and API documentation with [verb](https://github.com/verbose/verb):
+
+```sh
+$ npm install -g verb verb-readme-generator && verb
+```
+
+## Running tests
+
+Install dev dependencies:
+
+```sh
+$ npm install -d && npm test
+```
+
+## Author
+
+**Jon Schlinkert**
+
+* [github/jonschlinkert](https://github.com/jonschlinkert)
+* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+
+## License
+
+Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
+Released under the [MIT license](https://github.com/jonschlinkert/cache-base/blob/master/LICENSE).
+
+***
+
+_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on May 30, 2016._
\ No newline at end of file
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..473f5f3
--- /dev/null
+++ b/index.js
@@ -0,0 +1,245 @@
+'use strict';
+
+var utils = require('./utils');
+
+/**
+ * Create a `Cache` constructor that when instantiated will
+ * store values on the given `prop`.
+ *
+ * ```js
+ * var Cache = require('cache-base').namespace('data');
+ * var cache = new Cache();
+ *
+ * cache.set('foo', 'bar');
+ * //=> {data: {foo: 'bar'}}
+ * ```
+ * @param {String} `prop` The property name to use for storing values.
+ * @return {Function} Returns a custom `Cache` constructor
+ * @api public
+ */
+
+function namespace(prop) {
+
+ /**
+ * Create a new `Cache`. Internally the `Cache` constructor is created using
+ * the `namespace` function, with `cache` defined as the storage object.
+ *
+ * ```js
+ * var app = new Cache();
+ * ```
+ * @param {Object} `cache` Optionally pass an object to initialize with.
+ * @constructor
+ * @api public
+ */
+
+ function Cache(cache) {
+ if (prop) {
+ this[prop] = {};
+ }
+ if (cache) {
+ this.set(cache);
+ }
+ }
+
+ /**
+ * Inherit Emitter
+ */
+
+ utils.Emitter(Cache.prototype);
+
+ /**
+ * Assign `value` to `key`. Also emits `set` with
+ * the key and value.
+ *
+ * ```js
+ * app.on('set', function(key, val) {
+ * // do something when `set` is emitted
+ * });
+ *
+ * app.set(key, value);
+ *
+ * // also takes an object or array
+ * app.set({name: 'Halle'});
+ * app.set([{foo: 'bar'}, {baz: 'quux'}]);
+ * console.log(app);
+ * //=> {name: 'Halle', foo: 'bar', baz: 'quux'}
+ * ```
+ *
+ * @name .set
+ * @emits `set` with `key` and `value` as arguments.
+ * @param {String} `key`
+ * @param {any} `value`
+ * @return {Object} Returns the instance for chaining.
+ * @api public
+ */
+
+ Cache.prototype.set = function(key, val) {
+ if (Array.isArray(key) && arguments.length === 2) {
+ key = utils.toPath(key);
+ }
+ if (utils.isObject(key) || Array.isArray(key)) {
+ this.visit('set', key);
+ } else {
+ utils.set(prop ? this[prop] : this, key, val);
+ this.emit('set', key, val);
+ }
+ return this;
+ };
+
+ /**
+ * Union `array` to `key`. Also emits `set` with
+ * the key and value.
+ *
+ * ```js
+ * app.union('a.b', ['foo']);
+ * app.union('a.b', ['bar']);
+ * console.log(app.get('a'));
+ * //=> {b: ['foo', 'bar']}
+ * ```
+ * @name .union
+ * @param {String} `key`
+ * @param {any} `value`
+ * @return {Object} Returns the instance for chaining.
+ * @api public
+ */
+
+ Cache.prototype.union = function(key, val) {
+ if (Array.isArray(key) && arguments.length === 2) {
+ key = utils.toPath(key);
+ }
+ var ctx = prop ? this[prop] : this;
+ utils.union(ctx, key, utils.arrayify(val));
+ this.emit('union', val);
+ return this;
+ };
+
+ /**
+ * Return the value of `key`. Dot notation may be used
+ * to get [nested property values][get-value].
+ *
+ * ```js
+ * app.set('a.b.c', 'd');
+ * app.get('a.b');
+ * //=> {c: 'd'}
+ *
+ * app.get(['a', 'b']);
+ * //=> {c: 'd'}
+ * ```
+ *
+ * @name .get
+ * @emits `get` with `key` and `value` as arguments.
+ * @param {String} `key` The name of the property to get. Dot-notation may be used.
+ * @return {any} Returns the value of `key`
+ * @api public
+ */
+
+ Cache.prototype.get = function(key) {
+ key = utils.toPath(arguments);
+
+ var ctx = prop ? this[prop] : this;
+ var val = utils.get(ctx, key);
+
+ this.emit('get', key, val);
+ return val;
+ };
+
+ /**
+ * Return true if app has a stored value for `key`,
+ * false only if value is `undefined`.
+ *
+ * ```js
+ * app.set('foo', 'bar');
+ * app.has('foo');
+ * //=> true
+ * ```
+ *
+ * @name .has
+ * @emits `has` with `key` and true or false as arguments.
+ * @param {String} `key`
+ * @return {Boolean}
+ * @api public
+ */
+
+ Cache.prototype.has = function(key) {
+ key = utils.toPath(arguments);
+
+ var ctx = prop ? this[prop] : this;
+ var val = utils.get(ctx, key);
+
+ var has = typeof val !== 'undefined';
+ this.emit('has', key, has);
+ return has;
+ };
+
+ /**
+ * Delete one or more properties from the instance.
+ *
+ * ```js
+ * app.del(); // delete all
+ * // or
+ * app.del('foo');
+ * // or
+ * app.del(['foo', 'bar']);
+ * ```
+ * @name .del
+ * @emits `del` with the `key` as the only argument.
+ * @param {String|Array} `key` Property name or array of property names.
+ * @return {Object} Returns the instance for chaining.
+ * @api public
+ */
+
+ Cache.prototype.del = function(key) {
+ if (Array.isArray(key)) {
+ this.visit('del', key);
+ } else {
+ utils.del(prop ? this[prop] : this, key);
+ this.emit('del', key);
+ }
+ return this;
+ };
+
+ /**
+ * Reset the entire cache to an empty object.
+ *
+ * ```js
+ * app.clear();
+ * ```
+ * @api public
+ */
+
+ Cache.prototype.clear = function() {
+ if (prop) {
+ this[prop] = {};
+ }
+ };
+
+ /**
+ * Visit `method` over the properties in the given object, or map
+ * visit over the object-elements in an array.
+ *
+ * @name .visit
+ * @param {String} `method` The name of the `base` method to call.
+ * @param {Object|Array} `val` The object or array to iterate over.
+ * @return {Object} Returns the instance for chaining.
+ * @api public
+ */
+
+ Cache.prototype.visit = function(method, val) {
+ utils.visit(this, method, val);
+ return this;
+ };
+
+ return Cache;
+}
+
+/**
+ * Expose `Cache`
+ */
+
+module.exports = namespace();
+
+/**
+ * Expose `Cache.namespace`
+ */
+
+module.exports.namespace = namespace;
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..d53072b
--- /dev/null
+++ b/package.json
@@ -0,0 +1,79 @@
+{
+ "name": "cache-base",
+ "description": "Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects.",
+ "version": "0.8.4",
+ "homepage": "https://github.com/jonschlinkert/cache-base",
+ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
+ "repository": "jonschlinkert/cache-base",
+ "bugs": {
+ "url": "https://github.com/jonschlinkert/cache-base/issues"
+ },
+ "license": "MIT",
+ "files": [
+ "index.js",
+ "utils.js"
+ ],
+ "main": "index.js",
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "scripts": {
+ "test": "mocha"
+ },
+ "dependencies": {
+ "collection-visit": "^0.2.1",
+ "component-emitter": "^1.2.1",
+ "get-value": "^2.0.5",
+ "has-value": "^0.3.1",
+ "isobject": "^2.1.0",
+ "lazy-cache": "^2.0.1",
+ "set-value": "^0.3.3",
+ "to-object-path": "^0.3.0",
+ "union-value": "^0.2.3",
+ "unset-value": "^0.1.1"
+ },
+ "devDependencies": {
+ "gulp-format-md": "^0.1.8",
+ "mocha": "^2.4.5"
+ },
+ "keywords": [
+ "cache",
+ "config",
+ "data",
+ "get",
+ "has",
+ "hash",
+ "hasown",
+ "object",
+ "set",
+ "store"
+ ],
+ "verb": {
+ "run": true,
+ "toc": false,
+ "layout": "default",
+ "tasks": [
+ "readme"
+ ],
+ "plugins": [
+ "gulp-format-md"
+ ],
+ "related": {
+ "highligh": "base",
+ "list": [
+ "base-methods",
+ "get-value",
+ "has-value",
+ "option-cache",
+ "set-value",
+ "unset-value"
+ ]
+ },
+ "reflinks": [
+ "verb"
+ ],
+ "lint": {
+ "reflinks": true
+ }
+ }
+}
diff --git a/test/fixtures/a.yml b/test/fixtures/a.yml
new file mode 100644
index 0000000..f39056b
--- /dev/null
+++ b/test/fixtures/a.yml
@@ -0,0 +1 @@
+a: b
\ No newline at end of file
diff --git a/test/fixtures/data/alert.json b/test/fixtures/data/alert.json
new file mode 100644
index 0000000..31767e6
--- /dev/null
+++ b/test/fixtures/data/alert.json
@@ -0,0 +1,7 @@
+{
+ "success": {
+ "test": true,
+ "strong": "Heads up! This is a warning!",
+ "text": "You forgot a field!"
+ }
+}
\ No newline at end of file
diff --git a/test/fixtures/data/data.json b/test/fixtures/data/data.json
new file mode 100644
index 0000000..7cd0452
--- /dev/null
+++ b/test/fixtures/data/data.json
@@ -0,0 +1,3 @@
+{
+ "root": "Whoa, I should be at the root!"
+}
\ No newline at end of file
diff --git a/test/fixtures/data/test.json b/test/fixtures/data/test.json
new file mode 100644
index 0000000..c8e407b
--- /dev/null
+++ b/test/fixtures/data/test.json
@@ -0,0 +1,4 @@
+{
+ "alpha": "one",
+ "beta": "two"
+}
\ No newline at end of file
diff --git a/test/fixtures/namespace/a.yml b/test/fixtures/namespace/a.yml
new file mode 100644
index 0000000..3d94692
--- /dev/null
+++ b/test/fixtures/namespace/a.yml
@@ -0,0 +1 @@
+one: ${site.two}
\ No newline at end of file
diff --git a/test/fixtures/namespace/b.yml b/test/fixtures/namespace/b.yml
new file mode 100644
index 0000000..de0fc03
--- /dev/null
+++ b/test/fixtures/namespace/b.yml
@@ -0,0 +1 @@
+two: ${site.three}
\ No newline at end of file
diff --git a/test/fixtures/namespace/c.json b/test/fixtures/namespace/c.json
new file mode 100644
index 0000000..0eede4c
--- /dev/null
+++ b/test/fixtures/namespace/c.json
@@ -0,0 +1,3 @@
+{
+ "three": "data was processed!"
+}
\ No newline at end of file
diff --git a/test/test.js b/test/test.js
new file mode 100644
index 0000000..2619ad8
--- /dev/null
+++ b/test/test.js
@@ -0,0 +1,369 @@
+/*!
+ * cache-base <https://github.com/jonschlinkert/cache-base>
+ *
+ * Copyright (c) 2014-2015, Jon Schlinkert.
+ * Licensed under the MIT License.
+ */
+
+'use strict';
+
+require('mocha');
+var assert = require('assert');
+var Cache;
+var cache;
+var app;
+
+describe('cache-base', function() {
+ beforeEach(function() {
+ Cache = require('..');
+ app = new Cache();
+ });
+
+ describe('constructor:', function() {
+ it('should create an instance of Cache', function() {
+ assert(app instanceof Cache);
+ });
+
+ it('should set ', function() {
+ var app = new Cache({
+ one: 1,
+ two: 2
+ });
+ assert.equal(app.one, 1);
+ assert.equal(app.two, 2);
+ });
+ });
+
+ describe('get/set:', function() {
+ beforeEach(function() {
+ Cache = require('..');
+ app = new Cache();
+ });
+
+ afterEach(function() {
+ app.clear();
+ });
+
+ describe('set() - add:', function() {
+ it('should set a new property with the given value', function() {
+ app.set('one', 1);
+ assert.equal(app.get('one'), 1);
+ });
+ });
+
+ describe('set() - update:', function() {
+ it('should update an existing property with the given value', function() {
+ app.set('one', 2);
+ assert.equal(app.get('one'), 2);
+ });
+
+ it('should get the given property', function() {
+ app.set('a', 'b');
+ assert.equal(app.get('a'), 'b');
+ });
+ });
+ });
+
+ describe('.union()', function() {
+ it('should union a string value', function() {
+ app.union('a', 'b');
+ assert.deepEqual(app.get('a'), ['b']);
+ });
+
+ it('should union multiple string values', function() {
+ app.union('a', 'b');
+ app.union('a', 'c');
+ app.union('a', 'd');
+ assert.deepEqual(app.get('a'), ['b', 'c', 'd']);
+ });
+
+ it('should union multiple arrays', function() {
+ app.union('a', ['b']);
+ app.union('a', ['c']);
+ app.union('a', ['d']);
+ assert.deepEqual(app.get('a'), ['b', 'c', 'd']);
+ });
+
+ it('should union nested string values', function() {
+ app.union('a.b', 'b');
+ app.union('a.b', 'c');
+ app.union('a.b', 'd');
+ assert.deepEqual(app.get('a'), {b: ['b', 'c', 'd']});
+ });
+
+ it('should union and uniquify arrays', function() {
+ app.union('a.b', ['b', 'foo']);
+ app.union('a.b', ['c', 'foo']);
+ app.union('a.b', ['d', 'foo']);
+ assert.deepEqual(app.get('a'), {b: ['b', 'foo', 'c', 'd']});
+ });
+ });
+
+ describe('.set()', function() {
+ it('should set a value', function() {
+ app.set('a', 'b');
+ assert.equal(app.get('a'), 'b');
+ });
+
+ it('should set properties on the `cache` object.', function() {
+ app.set('a', 'b');
+ assert.equal(app.a, 'b');
+ });
+
+ it('should allow an object to be set directly.', function() {
+ app.set({x: 'y'});
+ assert.equal(app.x, 'y');
+ assert.equal(app.get('x'), 'y');
+ });
+
+ it('should set nested properties on the `cache` object.', function() {
+ app.set('c', {d: 'e'});
+ assert.equal(app.get('c').d, 'e');
+ });
+
+ it('should return `this` for chaining', function() {
+ assert.equal(app.set('a', 'b'), app);
+ app
+ .set('aa', 'bb')
+ .set('bb', 'cc')
+ .set('cc', 'dd');
+ assert.equal(app.get('aa'), 'bb');
+ assert.equal(app.get('bb'), 'cc');
+ assert.equal(app.get('cc'), 'dd');
+ });
+
+ it('should return undefined when not set', function() {
+ assert.equal(app.set('a', undefined), app);
+ });
+ });
+
+ describe('.get()', function() {
+ it('should return undefined when no set', function() {
+ assert(app.get('a') === undefined);
+ });
+
+ it('should get a value', function() {
+ app.set('a', 'b');
+ assert.equal(app.get('a'), 'b');
+ });
+
+ it('should get a nested property value', function() {
+ app.set('a.b.c', 'z');
+ assert.equal(app.a.b.c, 'z');
+ assert.deepEqual(app.get('a.b'), {c: 'z'});
+ });
+ });
+});
+
+describe('events', function() {
+ beforeEach(function() {
+ Cache = require('..');
+ app = new Cache();
+ });
+
+ describe('set', function() {
+ it('should emit a "set" event', function(cb) {
+ app.on('set', function(key, val) {
+ cb();
+ });
+ app.set('a', 'b');
+ });
+
+ it('should emit the key with "set" events', function(cb) {
+ app.on('set', function(key, val) {
+ assert.equal(key, 'a');
+ cb();
+ });
+ app.set('a', 'b');
+ });
+
+ it('should emit the value with "set" events', function(cb) {
+ app.on('set', function(key, val) {
+ assert.equal(val, 'b');
+ cb();
+ });
+ app.set('a', 'b');
+ });
+ });
+
+ describe('get', function() {
+ it('should emit a get event', function(cb) {
+ app.on('get', function(key) {
+ cb();
+ });
+ app.get('a');
+ });
+
+ it('should emit the key with "get" events', function(cb) {
+ app.on('get', function(key, val) {
+ assert.equal(key, 'a');
+ cb();
+ });
+ app.set('a', 'b');
+ app.get('a');
+ });
+
+ it('should emit the value with "get" events', function(cb) {
+ app.on('get', function(key, val) {
+ assert.equal(val, 'b');
+ cb();
+ });
+ app.set('a', 'b');
+ app.get('a');
+ });
+ });
+
+ describe('has', function() {
+ it('should emit a has event', function(cb) {
+ app.on('has', function(key) {
+ cb();
+ });
+ app.has('a');
+ });
+
+ it('should emit the key with "has" events', function(cb) {
+ app.on('has', function(key, val) {
+ assert.equal(key, 'a');
+ cb();
+ });
+ app.set('a', 'b');
+ app.has('a');
+ });
+
+ it('should emit the value with "has" events', function(cb) {
+ app.on('has', function(key, val) {
+ assert.equal(val, true);
+ cb();
+ });
+ app.set('a', 'b');
+ app.has('a');
+ });
+ });
+
+ describe('del', function() {
+ it('should emit a del event', function(cb) {
+ app.on('del', function(key) {
+ cb();
+ });
+ app.del('a');
+ });
+
+ it('should emit the key with "del" events', function(cb) {
+ app.on('del', function(key) {
+ assert.equal(key, 'a');
+ cb();
+ });
+ app.set('a', 'b');
+ app.del('a');
+ });
+
+ it('should emit each deleted key when an array is passed', function(cb) {
+ var keys = [];
+ app.on('del', function(key) {
+ keys.push(key);
+ });
+
+ app.set('a', 'b');
+ app.set('c', 'd');
+
+ app.del(['a', 'c']);
+ assert.deepEqual(keys, ['a', 'c']);
+ assert(!app.a);
+ assert(!app.c);
+ cb();
+ });
+ });
+});
+
+describe('namespace', function() {
+ beforeEach(function() {
+ cache = require('..');
+ Cache = cache.namespace('data');
+ app = new Cache();
+ });
+
+ describe('constructor:', function() {
+ it('should create an instance of Cache', function() {
+ assert(app instanceof Cache);
+ });
+
+ it('should set ', function() {
+ var app = new Cache({
+ one: 1,
+ two: 2
+ });
+ assert.equal(app.data.one, 1);
+ assert.equal(app.data.two, 2);
+ });
+ });
+
+ describe('get/set:', function() {
+ describe('set() - add:', function() {
+ it('should set a new property with the given value', function() {
+ app.set('one', 1);
+ assert.equal(app.get('one'), 1);
+ });
+ });
+
+ describe('set() - update:', function() {
+ it('should update an existing property with the given value', function() {
+ app.set('one', 2);
+ assert.equal(app.get('one'), 2);
+ });
+
+ it('should get the given property', function() {
+ app.set('a', 'b');
+ assert.equal(app.get('a'), 'b');
+ });
+ });
+ });
+
+ describe('.set()', function() {
+ it('should set a value', function() {
+ app.set('a', 'b');
+ assert.equal(app.get('a'), 'b');
+ });
+
+ it('should set properties on the `cache` object.', function() {
+ app.set('a', 'b');
+ assert.equal(app.data.a, 'b');
+ });
+
+ it('should allow an object to be set directly.', function() {
+ app.set({x: 'y'});
+ assert.equal(app.data.x, 'y');
+ assert.equal(app.get('x'), 'y');
+ });
+
+ it('should set nested properties on the `cache` object.', function() {
+ app.set('c', {d: 'e'});
+ assert.equal(app.get('c').d, 'e');
+ });
+
+ it('should return `this` for chaining', function() {
+ assert.equal(app.set('a', 'b'), app);
+ app
+ .set('aa', 'bb')
+ .set('bb', 'cc')
+ .set('cc', 'dd');
+ assert.equal(app.get('aa'), 'bb');
+ assert.equal(app.get('bb'), 'cc');
+ assert.equal(app.get('cc'), 'dd');
+ });
+
+ it('should return undefined when not set', function() {
+ assert.equal(app.set('a', undefined), app);
+ });
+ });
+
+ describe('.get()', function() {
+ it('should return undefined when no set', function() {
+ assert(app.get('a') === undefined);
+ });
+
+ it('should otherwise return the value', function() {
+ app.set('a', 'b');
+ assert.equal(app.get('a'), 'b');
+ });
+ });
+});
\ No newline at end of file
diff --git a/utils.js b/utils.js
new file mode 100644
index 0000000..5b1740a
--- /dev/null
+++ b/utils.js
@@ -0,0 +1,38 @@
+'use strict';
+
+/**
+ * Module dependencies
+ */
+
+var utils = require('lazy-cache')(require);
+var fn = require;
+require = utils;
+
+/**
+ * Lazily required module dependencies
+ */
+
+require('component-emitter', 'Emitter');
+require('collection-visit', 'visit');
+require('isobject', 'isObject');
+require('unset-value', 'del');
+require('get-value', 'get');
+require('has-value', 'has');
+require('set-value', 'set');
+require('union-value', 'union');
+require('to-object-path', 'toPath');
+require = fn;
+
+/**
+ * Cast val to an array
+ */
+
+utils.arrayify = function(val) {
+ return val ? (Array.isArray(val) ? val : [val]) : [];
+};
+
+/**
+ * Expose `utils` modules
+ */
+
+module.exports = utils;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-cache-base.git
More information about the Pkg-javascript-commits
mailing list