{"name":"cache-base","description":"Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects.","version":"0.7.1","homepage":"https://github.com/jonschlinkert/cache-base","author":{"name":"Jon Schlinkert","url":"https://github.com/jonschlinkert"},"repository":{"type":"git","url":"git+https://github.com/jonschlinkert/cache-base.git"},"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.0","get-value":"^2.0.0","has-value":"^0.3.0","isobject":"^2.0.0","lazy-cache":"^0.2.4","set-value":"^0.3.1","unset-value":"^0.1.1"},"devDependencies":{"mocha":"^2.3.4"},"keywords":["cache","config","data","get","has","hash","hasown","object","set","store"],"verb":{"related":{"list":["set-value","get-value","has-value","unset-value","base-methods","option-cache"]}},"gitHead":"36c215fc52d51682de92f509f3c05ac2085aa849","_id":"cache-base@0.7.1","_shasum":"11e3e39d7bf823d114bfb157ca96ce43fabb74b7","_from":".","_npmVersion":"3.3.6","_nodeVersion":"5.0.0","_npmUser":{"name":"jonschlinkert","email":"github@sellside.com"},"maintainers":[{"name":"jonschlinkert","email":"github@sellside.com"},{"name":"doowb","email":"brian.woodward@gmail.com"}],"dist":{"shasum":"11e3e39d7bf823d114bfb157ca96ce43fabb74b7","tarball":"http://registry-npm.ywwl.com/cache-base/download/cache-base-0.7.1.tgz","integrity":"sha512-ckPncnLHPN5CXA6D/ama4ibmA75kG6D5riMLKcK9ihyDs+i3lEKJtZoxs6TvD3LStL04xPcH5IPxrvxH1diioA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICfGlNjgYYtfldTkY8BiuFGCZGqawGMKOCJPO6BGy+p3AiEAsAEovDzxv3acf28u1xUC+mWuzhnoSv/kmLsbZ0UrySk="}],"size":3914,"noattachment":false,"key":"/cache-base/-/cache-base-0.7.1.tgz"},"directories":{},"readme":"# 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)\n\n> Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n- [Install](#install)\n- [Quickstart](#quickstart)\n- [API](#api)\n- [Usage examples](#usage-examples)\n- [About](#about)\n\n_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save cache-base\n```\n\n## Quickstart\n\n```js\nconst CacheBase = require('cache-base');\nconst app = new CacheBase();\n\napp.set('a.b', 'c');\n\nconsole.log(app.cache.a);    //=> { b: 'c' }\nconsole.log(app.cache.a.b);  //=> 'c'\n\nconsole.log(app.get('a'));   //=> { b: 'c' }\nconsole.log(app.get('a.b')); //=> 'c'\n```\n\nMore [usage examples](#usage-examples) below.\n\n## API\n\n**Params**\n\n* `prop` **{String|Object}**: (optional) Property name to use for the cache, or the object to initialize with.\n* `cache` **{Object}**: (optional) An object to initialize with.\n\n**Example**\n\n```js\nconst app = new CacheBase();\n```\n\n### [.set](index.js#L65)\n\nAssign `value` to `key`. Also emits `set` with the key and value.\n\n**Params**\n\n* `key` **{String|Array}**: The name of the property to set. Dot-notation may be used to set nested properties.\n* `value` **{any}**\n* `returns` **{Object}**: Returns the instance for chaining.\n\n**Events**\n\n* `emits`: `set` with `key` and `value` as arguments.\n\n**Example**\n\n```js\napp.on('set', function(key, val) {\n  // do something when `set` is emitted\n});\n\napp.set('admin', true);\n\n// also takes an object or an array of objects\napp.set({ name: 'Brian' });\napp.set([{ foo: 'bar' }, { baz: 'quux' }]);\nconsole.log(app);\n//=> { name: 'Brian', foo: 'bar', baz: 'quux' }\n```\n\n### [.get](index.js#L90)\n\nReturn the value of `key`.\n\n**Params**\n\n* `key` **{String|Array}**: The name of the property to get. Dot-notation may be used to set nested properties.\n* `returns` **{any}**: Returns the value of `key`\n\n**Events**\n\n* `emits`: `get` with `key` and `value` as arguments.\n\n**Example**\n\n```js\napp.set('a.b.c', 'd');\napp.get('a.b');\n//=> { c: 'd' }\n```\n\n### [.prime](index.js#L120)\n\nCreate a property on the cache with the given `value` only if it doesn't already exist.\n\n**Params**\n\n* `key` **{String}**: Property name or object path notation.\n* `val` **{any}**\n* `returns` **{Object}**: Returns the instance for chaining.\n\n**Example**\n\n```js\nconsole.log(app.cache); //=> {}\napp.set('one', { foo: 'bar' });\napp.prime('one', { a: 'b' });\napp.prime('two', { c: 'd' });\nconsole.log(app.cache.one); //=> { foo: 'bar' }\nconsole.log(app.cache.two); //=> { c: 'd' }\n```\n\n### [.default](index.js#L162)\n\nSet a default value to be used when `.get()` is called and the value is not defined on the cache. Returns a value from the defaults when only a key is passed.\n\n**Params**\n\n* `key` **{String|Array}**: The name of the property to set. Dot-notation may be used to set nested properties.\n* `value` **{any}**: (optional) The value to set on the defaults object.\n* `returns` **{Object}**: Returns the instance for chaining.\n\n**Example**\n\n```js\napp.set('foo', 'xxx');\napp.default('foo', 'one');\napp.default('bar', 'two');\napp.default('baz', 'three');\napp.set('baz', 'zzz');\n\nconsole.log(app.get('foo'));\n//=> 'xxx'\n\nconsole.log(app.get('bar'));\n//=> 'two'\n\nconsole.log(app.get('baz'));\n//=> 'zzz'\n\nconsole.log(app);\n// CacheBase {\n//   cache: { foo: 'xxx', bar: 'two', baz: 'zzz' },\n//   defaults: { foo: 'one', bar: 'two', baz: 'three' } }\n```\n\n### [.union](index.js#L199)\n\nSet an array of unique values on cache `key`.\n\n**Params**\n\n* `key` **{String|Array}**: The name of the property to union. Dot-notation may be used to set nested properties.\n* `value` **{any}**\n* `returns` **{Object}**: Returns the instance for chaining.\n\n**Example**\n\n```js\napp.union('a.b.c', 'foo');\napp.union('a.b.c', 'bar');\napp.union('a.b.c', ['bar', 'baz']);\nconsole.log(app.get('a'));\n//=> { b: { c: ['foo', 'bar', 'baz'] } }\n```\n\n### [.has](index.js#L223)\n\nReturn true if the value of property `key` is not `undefined`.\n\n**Params**\n\n* `key` **{String|Array}**: The name of the property to check. Dot-notation may be used to set nested properties.\n* `returns` **{Boolean}**\n\n**Example**\n\n```js\napp.set('foo', true);\napp.set('baz', null);\napp.set('bar', undefined);\n\napp.has('foo'); //=> true\napp.has('bar'); //=> true\napp.has('baz'); //=> false\n```\n\n### [.hasOwn](index.js#L253)\n\nReturns true if the specified property is an own (not inherited) property. Similar to [.has()](#has), but returns true if the key exists, even if the value is `undefined`.\n\n**Params**\n\n* `key` **{String}**\n* `returns` **{Boolean}**: Returns true if object `key` exists. Dot-notation may be used to set nested properties.\n\n**Example**\n\n```js\napp.set('a.b.c', 'd');\napp.set('x', false);\napp.set('y', null);\napp.set('z', undefined);\n\napp.hasOwn('a');      //=> true\napp.hasOwn('b');      //=> true\napp.hasOwn('c');      //=> true\napp.hasOwn('a.b.c');  //=> true\napp.hasOwn('x');      //=> true\napp.hasOwn('y');      //=> true\napp.hasOwn('z');      //=> true\napp.hasOwn('lslsls'); //=> false\n```\n\n### [.del](index.js#L278)\n\nDelete one or more properties from the instance.\n\n**Params**\n\n* `key` **{String|Array}**: The name of the property to delete. Dot-notation may be used to set nested properties.\n* `returns` **{Object}**: Returns the instance for chaining.\n\n**Events**\n\n* `emits`: `del` with the `key` as the only argument.\n\n**Example**\n\n```js\n// setup a listener to update a property with a default\n// value when it's deleted by the user\napp.on('del', key => app.set(key, app.default(key)));\n\napp.del(); // delete all properties on the cache\n// or\napp.del('foo');\n// or an array of keys\napp.del(['foo', 'bar']);\n```\n\n### [.clear](index.js#L301)\n\nReset the entire cache to an empty object. Note that this does not also clear the `defaults` object, since you can manually do `cache.defaults = {}` if you want to reset that object as well.\n\n**Example**\n\n```js\n// clear \"defaults\" whenever the cache is cleared\napp.on('clear', key => (app.defaults = {}));\napp.clear();\n```\n\n### [.visit](index.js#L318)\n\nVisit (or map visit) the specified method (`key`) over the properties in the\ngiven object or array.\n\n**Params**\n\n* `key` **{String|Array}**: The name of the method to visit.\n* `val` **{Object|Array}**: The object or array to iterate over.\n* `returns` **{Object}**: Returns the instance for chaining.\n\n### [.keys](index.js#L338)\n\nGets an array of names of all enumerable properties on the cache.\n\n**Example**\n\n```js\nconst app = new CacheBase();\napp.set('user', true);\napp.set('admin', false);\n\nconsole.log(app.keys);\n//=> ['user', 'admin']\n```\n\n### [.size](index.js#L357)\n\nGets the length of [keys](#keys).\n\n**Example**\n\n```js\nconst app = new CacheBase();\napp.set('user', true);\napp.set('admin', false);\n\nconsole.log(app.size);\n//=> 2\n```\n\n## Usage examples\n\n**Create an instance of cache-base**\n\n```js\nconst app = new CacheBase();\n\napp.set('a', 'b');\napp.set('c.d', 'e');\n\nconsole.log(app.get('a'));\n//=> 'b'\nconsole.log(app.get('c'));\n//=> { d: 'e' }\nconsole.log(app);\n//=> CacheBase { a: 'b' }\n```\n\n**Initialize with an object**\n\n```js\nconst app = new CacheBase({ a: 'b', c: { d: 'e' } });\n\nconsole.log(app.get('a'));\n//=> 'b'\nconsole.log(app.get('c'));\n//=> { d: 'e' }\nconsole.log(app.get('c.d'));\n//=> 'e'\nconsole.log(app);\n//=> CacheBase { cache: { a: 'b' } }\n```\n\n**Inherit**\n\n```js\nclass MyApp extends CacheBase {}\n\nconst app = new MyApp();\napp.set('a', 'b');\napp.set('c', 'd');\n\nconsole.log(app.get('a'));\n//=> 'b'\n\nconsole.log(app);\n//=> MyApp { cache: { a: 'b', c: 'd' } }\n```\n\n**Custom namespace**\n\nPass a string as the first value to the contructor to define a custom property name to use for the cache. By default values are stored on the `cache` property.\n\n```js\nconst CacheBase = require('cache-base');\nconst app = new CacheBase('data', { a: 'b' });\napp.set('c.d', 'e');\n\n// get values\nconsole.log(app.get('a'));\n//=> 'b'\nconsole.log(app.get('c'));\n//=> { d: 'e' }\nconsole.log(app.data);\n//=> { a: 'b', c: { d: 'e' } }\nconsole.log(app);\n//=> CacheBase { data: { a: 'b', c: { d: 'e' } } }\n```\n\n## About\n\n<details>\n<summary><strong>Contributing</strong></summary>\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n</details>\n\n<details>\n<summary><strong>Running Tests</strong></summary>\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install && npm test\n```\n\n</details>\n\n<details>\n<summary><strong>Building docs</strong></summary>\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme && verb\n```\n\n</details>\n\n### Related projects\n\nYou might also be interested in these projects:\n\n* [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://github.com/jonschlinkert/base-methods) | [homepage](https://github.com/jonschlinkert/base-methods \"base-methods is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting with a handful of common methods, like `set`, `get`, `del` and `use`.\")\n* [get-value](https://www.npmjs.com/package/get-value): Use property paths like 'a.b.c' to get a nested value from an object. Even works… [more](https://github.com/jonschlinkert/get-value) | [homepage](https://github.com/jonschlinkert/get-value \"Use property paths like 'a.b.c' to get a nested value from an object. Even works when keys have dots in them (no other dot-prop library can do this!).\")\n* [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://github.com/jonschlinkert/has-value) | [homepage](https://github.com/jonschlinkert/has-value \"Returns true if a value exists, false if empty. Works with deeply nested values using object paths.\")\n* [option-cache](https://www.npmjs.com/package/option-cache): Simple API for managing options in JavaScript applications. | [homepage](https://github.com/jonschlinkert/option-cache \"Simple API for managing options in JavaScript applications.\")\n* [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 \"Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.\")\n* [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 \"Delete nested properties from an object using dot notation.\")\n\n### Contributors\n\n| **Commits** | **Contributor** | \n| --- | --- |\n| 67 | [jonschlinkert](https://github.com/jonschlinkert) |\n| 2 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |\n\n### Author\n\n**Jon Schlinkert**\n\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on March 23, 2018._","publish_time":1448336888695,"_cnpm_publish_time":1448336888695,"dist-tags":{"latest":"4.0.2"}}