pax_global_header00006660000000000000000000000064127227626130014522gustar00rootroot0000000000000052 comment=38bec2e70f8fbd041ded5fea817551b7f890df9e cache-base-master/000077500000000000000000000000001272276261300143325ustar00rootroot00000000000000cache-base-master/.editorconfig000066400000000000000000000006461272276261300170150ustar00rootroot00000000000000# 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 cache-base-master/.eslintrc.json000066400000000000000000000111251272276261300171260ustar00rootroot00000000000000{ "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" ] } } cache-base-master/.gitattributes000066400000000000000000000001771272276261300172320ustar00rootroot00000000000000# Enforce Unix newlines * text eol=lf # binaries *.ai binary *.psd binary *.jpg binary *.gif binary *.png binary *.jpeg binarycache-base-master/.gitignore000066400000000000000000000001601272276261300163170ustar00rootroot00000000000000*.DS_Store *.sublime-* _gh_pages bower_components node_modules npm-debug.log temp test/actual tmp TODO.md vendorcache-base-master/.travis.yml000066400000000000000000000002471272276261300164460ustar00rootroot00000000000000sudo: 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' cache-base-master/.verb.md000066400000000000000000000013211272276261300156650ustar00rootroot00000000000000## 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") %} cache-base-master/LICENSE000066400000000000000000000021001272276261300153300ustar00rootroot00000000000000The 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. cache-base-master/README.md000066400000000000000000000154051272276261300156160ustar00rootroot00000000000000# cache-base [![NPM version](https://img.shields.io/npm/v/cache-base.svg?style=flat)](https://www.npmjs.com/package/cache-base) [![NPM downloads](https://img.shields.io/npm/dm/cache-base.svg?style=flat)](https://npmjs.org/package/cache-base) [![Build Status](https://img.shields.io/travis/jonschlinkert/cache-base.svg?style=flat)](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._cache-base-master/index.js000066400000000000000000000124531272276261300160040ustar00rootroot00000000000000'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; cache-base-master/package.json000066400000000000000000000030601272276261300166170ustar00rootroot00000000000000{ "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 } } } cache-base-master/test/000077500000000000000000000000001272276261300153115ustar00rootroot00000000000000cache-base-master/test/fixtures/000077500000000000000000000000001272276261300171625ustar00rootroot00000000000000cache-base-master/test/fixtures/a.yml000066400000000000000000000000041272276261300201170ustar00rootroot00000000000000a: bcache-base-master/test/fixtures/data/000077500000000000000000000000001272276261300200735ustar00rootroot00000000000000cache-base-master/test/fixtures/data/alert.json000066400000000000000000000001701272276261300220730ustar00rootroot00000000000000{ "success": { "test": true, "strong": "Heads up! This is a warning!", "text": "You forgot a field!" } }cache-base-master/test/fixtures/data/data.json000066400000000000000000000000561272276261300217000ustar00rootroot00000000000000{ "root": "Whoa, I should be at the root!" }cache-base-master/test/fixtures/data/test.json000066400000000000000000000000451272276261300217440ustar00rootroot00000000000000{ "alpha": "one", "beta": "two" }cache-base-master/test/fixtures/namespace/000077500000000000000000000000001272276261300211165ustar00rootroot00000000000000cache-base-master/test/fixtures/namespace/a.yml000066400000000000000000000000201272276261300220510ustar00rootroot00000000000000one: ${site.two}cache-base-master/test/fixtures/namespace/b.yml000066400000000000000000000000221272276261300220540ustar00rootroot00000000000000two: ${site.three}cache-base-master/test/fixtures/namespace/c.json000066400000000000000000000000441272276261300222310ustar00rootroot00000000000000{ "three": "data was processed!" }cache-base-master/test/test.js000066400000000000000000000215251272276261300166330ustar00rootroot00000000000000/*! * 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'); }); }); });cache-base-master/utils.js000066400000000000000000000012431272276261300160300ustar00rootroot00000000000000'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;