[Pkg-javascript-commits] [node-cache-base] 01/07: New upstream version 2.0.2
Praveen Arimbrathodiyil
praveen at moszumanska.debian.org
Sat Jan 13 07:51:31 UTC 2018
This is an automated email from the git hooks/post-receive script.
praveen pushed a commit to branch master
in repository node-cache-base.
commit 5aa33729d0b6ddc63e2c169262b9185952eeebc7
Author: Pirate Praveen <praveen at debian.org>
Date: Wed Jan 10 12:49:07 2018 +0530
New upstream version 2.0.2
---
.editorconfig | 18 ++---
.eslintrc.json | 228 ++++++++--------------------------------------------
.gitignore | 27 ++++++-
.travis.yml | 13 +--
.verb.md | 74 +++++++++++------
CHANGELOG.md | 140 ++++++++++++++++++++++++++++++++
LICENSE | 2 +-
README.md | 247 ++++++++++++++++++++++++++++++---------------------------
index.js | 209 +++++++++++++++++++++++-------------------------
package.json | 31 ++++----
test/test.js | 48 ++++++-----
utils.js | 38 ---------
12 files changed, 536 insertions(+), 539 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index 408d870..449f0da 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,22 +1,14 @@
-# http://editorconfig.org
+# http://editorconfig.org/
root = true
[*]
-indent_style = space
-end_of_line = lf
charset = utf-8
+end_of_line = lf
indent_size = 2
-trim_trailing_whitespace = true
+indent_style = space
insert_final_newline = true
+trim_trailing_whitespace = true
-[*.md]
-trim_trailing_whitespace = false
-insert_final_newline = false
-
-[**/{actual,fixtures,expected}/**]
-trim_trailing_whitespace = false
-insert_final_newline = false
-
-[**/templates/**]
+[{**/{actual,fixtures,expected,templates}/**,*.md}]
trim_trailing_whitespace = false
insert_final_newline = false
diff --git a/.eslintrc.json b/.eslintrc.json
index 5b78706..61e8895 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -1,107 +1,36 @@
{
- "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"
- ],
+ "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"
- ],
+ "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
- }
- ],
+ "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,
@@ -121,18 +50,12 @@
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
- "no-extra-parens": [
- 2,
- "functions"
- ],
+ "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-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
@@ -142,12 +65,7 @@
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
- "no-multiple-empty-lines": [
- 2,
- {
- "max": 1
- }
- ],
+ "no-multiple-empty-lines": [2, { "max": 1 }],
"no-native-reassign": 0,
"no-negated-in-lhs": 2,
"no-new": 2,
@@ -173,103 +91,27 @@
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
- "no-unneeded-ternary": [
- 2,
- {
- "defaultAssignment": false
- }
- ],
+ "no-unneeded-ternary": [2, { "defaultAssignment": false }],
"no-unreachable": 2,
- "no-unused-vars": [
- 2,
- {
- "vars": "all",
- "args": "none"
- }
- ],
+ "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"
- ],
+ "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"
- ],
+ "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",
- "!",
- ","
- ]
- }
- ],
+ "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"
- ]
+ "wrap-iife": [2, "any"],
+ "yoda": [2, "never"]
}
}
diff --git a/.gitignore b/.gitignore
index 9e685a4..f969a2c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,11 +1,30 @@
+# always ignore files
*.DS_Store
+.idea
+.vscode
*.sublime-*
-_gh_pages
-bower_components
+
+# test related, or directories generated by tests
+test/actual
+actual
+coverage
+.nyc*
+
+# npm
node_modules
npm-debug.log
+
+# yarn
+yarn.lock
+yarn-error.log
+
+# misc
+_gh_pages
+_draft
+_drafts
+bower_components
+vendor
temp
-test/actual
tmp
TODO.md
-vendor
\ No newline at end of file
+package-lock.json
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index cb1d261..1686664 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,15 @@
sudo: false
+os:
+ - linux
+ - osx
language: node_js
node_js:
+ - node
+ - '9'
+ - '8'
+ - '7'
+ - '6'
- '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
index 5bd2017..5b05b09 100644
--- a/.verb.md
+++ b/.verb.md
@@ -1,52 +1,74 @@
## Usage
```js
-var Cache = require('{%= name %}');
+const Cache = require('cache-base');
+```
+
+**Instantiate**
+```js
// instantiate
-var app = new Cache();
+const cache = new Cache();
// set values
-app.set('a', 'b');
-app.set('c.d', 'e');
+cache.set('a', 'b');
+cache.set('c.d', 'e');
// get values
-app.get('a');
+console.log(cache.get('a'));
//=> 'b'
-app.get('c');
-//=> {d: 'e'}
+console.log(cache.get('c'));
+//=> { d: 'e' }
+console.log(cache);
+//=> Cache { a: 'b' }
+```
+
+**Initialize with an object**
+
+```js
+// instantiate
+const cache = new Cache({ a: 'b', c: { d: 'e' } });
-console.log(app.cache);
-//=> {a: 'b'}
+// get values
+console.log(cache.get('a'));
+//=> 'b'
+console.log(cache.get('c'));
+//=> { d: 'e' }
+console.log(cache.get('c.d'));
+//=> 'e'
+console.log(cache);
+//=> Cache { a: 'b' }
```
**Inherit**
```js
-var util = require('util');
-var Cache = require('{%= name %}');
-
-function MyApp() {
- Cache.call(this);
-}
-util.inherits(MyApp, Cache);
+class MyApp extends Cache {}
-var app = new MyApp();
-app.set('a', 'b');
-app.get('a');
+var cache = new MyApp();
+cache.set('a', 'b');
+console.log(cache.get('a'));
//=> 'b'
```
-**Namespace**
+**Custom namespace**
-Define a custom property for storing values.
+Define a custom property name for storing values. By default, values are stored directly on the instance (for example, when `cache.set('foo', 'bar')` is used, `cache.foo` would be `bar`).
```js
-var Cache = require('{%= name %}').namespace('data');
-var app = new Cache();
-app.set('a', 'b');
-console.log(app.data);
-//=> {a: 'b'}
+const Cache = require('cache-base');
+const cache = new Cache('data', { a: 'b' });
+cache.set('c.d', 'e');
+
+// get values
+console.log(cache.get('a'));
+//=> 'b'
+console.log(cache.get('c'));
+//=> { d: 'e' }
+console.log(cache.data);
+//=> { a: 'b', c: { d: 'e' } }
+console.log(cache);
+//=> Cache { data: { a: 'b', c: { d: 'e' } } }
```
## API
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..29f15df
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,140 @@
+# Release history
+
+All notable changes to this project will be documented in this file.
+
+This changelog's format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
+and versioning in this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
+
+<details>
+ <summary><strong>Guiding Principles</strong></summary>
+
+- Changelogs are for humans, not machines.
+- There should be an entry for every single version.
+- The same types of changes should be grouped.
+- Versions and sections should be linkable.
+- The latest version comes first.
+- The release date of each versions is displayed.
+- Mention whether you follow Semantic Versioning.
+
+</details>
+
+<details>
+ <summary><strong>Types of changes</strong></summary>
+
+Changelog entries are classified using the following labels _(from [keep-a-changelog](http://keepachangelog.com/)_):
+
+- `Added` for new features.
+- `Changed` for changes in existing functionality.
+- `Deprecated` for soon-to-be removed features.
+- `Removed` for now removed features.
+- `Fixed` for any bug fixes.
+- `Security` in case of vulnerabilities.
+
+</details>
+
+
+## [2.0.0] - 2017-12-17
+
+**Changed**
+
+- convert to class
+- refactor to allow namespace to be set on constructor, thus `.namespace` was removed from the main export. Please see the readme for details.
+
+## [1.0.1] - 2017-07-22
+
+- run update, lint, update deps
+
+## [1.0.0] - 2017-02-25
+
+-
+
+## [0.8.5] - 2017-02-25
+
+- Bump `isobject`.
+- Bump `set-value`.
+- Merge pull request #7 from wtgtybhertgeghgtwtg/bump-dependencies
+- run udpate
+
+## [0.8.4] - 2016-05-30
+
+- run update
+- adds `.union` method. resolves https://github.com/jonschlinkert/cache-base/issues/3
+- generate docs
+- run update, update deps
+- make `.union` key behavior consistent with other methods
+- generate docs
+
+## [0.8.2] - 2016-03-02
+
+- handle single arg key as an array
+- generate docs
+
+## [0.8.1] - 2016-02-29
+
+- ensure value is a non-array object, only clear if `prop` is defined
+
+## [0.8.0] - 2016-02-09
+
+- run update
+- run update, lint
+- minor refactor
+- generate docs with verb
+
+## [0.7.1] - 2015-11-23
+
+- update deps
+- lint
+- adds lazy-cache, event emitting
+- events tests
+
+## [0.7.0] - 2015-11-23
+
+- use eslint, lint
+- refactor, simplify
+
+## [0.6.0] - 2015-03-11
+
+- fix pick docs
+- lint
+- get rid of deps
+
+## [0.4.0] - 2015-02-14
+
+- adds `.pick()` and `.omit()` methods
+- adds tests
+- build docs/readme
+
+## [0.3.0] - 2015-02-13
+
+- adds npmignore
+- adds travis
+- rename
+- copyright year, lint
+- update deps
+- build readme
+
+## [0.2.0] - 2014-11-15
+
+- first commit
+- remove namespace stuff
+- update fixtures
+- update verbfile
+- clean up, refactor a number of methods:
+- update docs, run verb
+
+[2.0.0]: https://github.com/jonschlinkert/cache-base/compare/1.0.1...2.0.0
+[1.0.1]: https://github.com/jonschlinkert/cache-base/compare/1.0.0...1.0.1
+[1.0.0]: https://github.com/jonschlinkert/cache-base/compare/0.8.5...1.0.0
+[0.8.5]: https://github.com/jonschlinkert/cache-base/compare/0.8.4...0.8.5
+[0.8.4]: https://github.com/jonschlinkert/cache-base/compare/0.8.2...0.8.4
+[0.8.2]: https://github.com/jonschlinkert/cache-base/compare/0.8.1...0.8.2
+[0.8.1]: https://github.com/jonschlinkert/cache-base/compare/0.8.0...0.8.1
+[0.8.0]: https://github.com/jonschlinkert/cache-base/compare/0.7.1...0.8.0
+[0.7.1]: https://github.com/jonschlinkert/cache-base/compare/0.7.0...0.7.1
+[0.7.0]: https://github.com/jonschlinkert/cache-base/compare/0.6.0...0.7.0
+[0.6.0]: https://github.com/jonschlinkert/cache-base/compare/0.4.0...0.6.0
+[0.4.0]: https://github.com/jonschlinkert/cache-base/compare/0.3.0...0.4.0
+[0.3.0]: https://github.com/jonschlinkert/cache-base/compare/0.2.0...0.3.0
+
+[keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog
+
diff --git a/LICENSE b/LICENSE
index 39245ac..3f2eca1 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2014-2016, Jon Schlinkert.
+Copyright (c) 2014-2017, 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
diff --git a/README.md b/README.md
index 94d7811..fbcbec2 100644
--- a/README.md
+++ b/README.md
@@ -1,90 +1,91 @@
-# 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)
+# 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 [...]
-Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects.
+> Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects.
+
+Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
-$ npm install cache-base --save
+$ npm install --save cache-base
```
## Usage
```js
-var Cache = require('cache-base');
+const Cache = require('cache-base');
+```
+
+**Instantiate**
+```js
// instantiate
-var app = new Cache();
+const cache = new Cache();
// set values
-app.set('a', 'b');
-app.set('c.d', 'e');
+cache.set('a', 'b');
+cache.set('c.d', 'e');
// get values
-app.get('a');
+console.log(cache.get('a'));
//=> 'b'
-app.get('c');
-//=> {d: 'e'}
-
-console.log(app.cache);
-//=> {a: 'b'}
+console.log(cache.get('c'));
+//=> { d: 'e' }
+console.log(cache);
+//=> Cache { a: 'b' }
```
-**Inherit**
+**Initialize with an object**
```js
-var util = require('util');
-var Cache = require('cache-base');
-
-function MyApp() {
- Cache.call(this);
-}
-util.inherits(MyApp, Cache);
+// instantiate
+const cache = new Cache({ a: 'b', c: { d: 'e' } });
-var app = new MyApp();
-app.set('a', 'b');
-app.get('a');
+// get values
+console.log(cache.get('a'));
//=> 'b'
+console.log(cache.get('c'));
+//=> { d: 'e' }
+console.log(cache.get('c.d'));
+//=> 'e'
+console.log(cache);
+//=> Cache { a: 'b' }
```
-**Namespace**
-
-Define a custom property for storing values.
+**Inherit**
```js
-var Cache = require('cache-base').namespace('data');
-var app = new Cache();
-app.set('a', 'b');
-console.log(app.data);
-//=> {a: 'b'}
-```
+class MyApp extends Cache {}
-## API
-
-### [namespace](index.js#L21)
-
-Create a `Cache` constructor that when instantiated will store values on the given `prop`.
-
-**Params**
+var cache = new MyApp();
+cache.set('a', 'b');
+console.log(cache.get('a'));
+//=> 'b'
+```
-* `prop` **{String}**: The property name to use for storing values.
-* `returns` **{Function}**: Returns a custom `Cache` constructor
+**Custom namespace**
-**Example**
+Define a custom property name for storing values. By default, values are stored directly on the instance (for example, when `cache.set('foo', 'bar')` is used, `cache.foo` would be `bar`).
```js
-var Cache = require('cache-base').namespace('data');
-var cache = new Cache();
+const Cache = require('cache-base');
+const cache = new Cache('data', { a: 'b' });
+cache.set('c.d', 'e');
-cache.set('foo', 'bar');
-//=> {data: {foo: 'bar'}}
+// get values
+console.log(cache.get('a'));
+//=> 'b'
+console.log(cache.get('c'));
+//=> { d: 'e' }
+console.log(cache.data);
+//=> { a: 'b', c: { d: 'e' } }
+console.log(cache);
+//=> Cache { data: { a: 'b', c: { d: 'e' } } }
```
-### [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.
+## API
**Params**
@@ -93,16 +94,16 @@ Create a new `Cache`. Internally the `Cache` constructor is created using the `n
**Example**
```js
-var app = new Cache();
+const cache = new Cache();
```
-### [.set](index.js#L76)
+### [.set](index.js#L65)
Assign `value` to `key`. Also emits `set` with the key and value.
**Params**
-* `key` **{String}**
+* `key` **{String|Array}**: The name of the property to set. Dot-notation or an array of object path segments may be used.
* `value` **{any}**
* `returns` **{Object}**: Returns the instance for chaining.
@@ -113,45 +114,45 @@ Assign `value` to `key`. Also emits `set` with the key and value.
**Example**
```js
-app.on('set', function(key, val) {
+cache.on('set', function(key, val) {
// do something when `set` is emitted
});
-app.set(key, value);
+cache.set(key, value);
// also takes an object or array
-app.set({name: 'Halle'});
-app.set([{foo: 'bar'}, {baz: 'quux'}]);
-console.log(app);
+cache.set({name: 'Halle'});
+cache.set([{foo: 'bar'}, {baz: 'quux'}]);
+console.log(cache);
//=> {name: 'Halle', foo: 'bar', baz: 'quux'}
```
-### [.union](index.js#L106)
+### [.union](index.js#L95)
Union `array` to `key`. Also emits `set` with the key and value.
**Params**
-* `key` **{String}**
+* `key` **{String|Array}**: The name of the property to union. Dot-notation or an array of object path segments may be used.
* `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'));
+cache.union('a.b', ['foo']);
+cache.union('a.b', ['bar']);
+console.log(cache.get('a'));
//=> {b: ['foo', 'bar']}
```
-### [.get](index.js#L136)
+### [.get](index.js#L125)
-Return the value of `key`. Dot notation may be used to get [nested property values][get-value].
+Return the value of `key`. Dot notation may be used to get [nested property values](https://github.com/jonschlinkert/get-value).
**Params**
-* `key` **{String}**: The name of the property to get. Dot-notation may be used.
+* `key` **{String|Array}**: The name of the property to get. Dot-notation or an array of object path segments may be used.
* `returns` **{any}**: Returns the value of `key`
**Events**
@@ -161,21 +162,21 @@ Return the value of `key`. Dot notation may be used to get [nested property valu
**Example**
```js
-app.set('a.b.c', 'd');
-app.get('a.b');
-//=> {c: 'd'}
+cache.set('a.b.c', 'd');
+cache.get('a.b');
+//=> { c: 'd' }
-app.get(['a', 'b']);
-//=> {c: 'd'}
+cache.get(['a', 'b']);
+//=> { c: 'd' }
```
-### [.has](index.js#L163)
+### [.has](index.js#L155)
-Return true if app has a stored value for `key`, false only if value is `undefined`.
+Return true if cache has a stored value for `key`, false only if value is `undefined`.
**Params**
-* `key` **{String}**
+* `key` **{String|Array}**: The name of the property to check. Dot-notation or an array of object path segments may be used.
* `returns` **{Boolean}**
**Events**
@@ -185,18 +186,18 @@ Return true if app has a stored value for `key`, false only if value is `undefin
**Example**
```js
-app.set('foo', 'bar');
-app.has('foo');
+cache.set('foo', 'bar');
+cache.has('foo');
//=> true
```
-### [.del](index.js#L191)
+### [.del](index.js#L183)
Delete one or more properties from the instance.
**Params**
-* `key` **{String|Array}**: Property name or array of property names.
+* `key` **{String|Array}**: The name of the property to delete. Dot-notation or an array of object path segments may be used.
* `returns` **{Object}**: Returns the instance for chaining.
**Events**
@@ -206,79 +207,93 @@ Delete one or more properties from the instance.
**Example**
```js
-app.del(); // delete all
+cache.del(); // delete all
// or
-app.del('foo');
+cache.del('foo');
// or
-app.del(['foo', 'bar']);
+cache.del(['foo', 'bar']);
```
-### [.clear](index.js#L210)
-
-Reset the entire cache to an empty object.
-
-**Example**
-
-```js
-app.clear();
-```
-
-### [.visit](index.js#L227)
+### [.visit](index.js#L204)
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.
+* `key` **{String|Array}**: The name of the method to visit. Dot-notation or an array of object path segments may be used.
* `val` **{Object|Array}**: The object or array to iterate over.
* `returns` **{Object}**: Returns the instance for chaining.
-## Related projects
+**Example**
-You might also be interested in these projects:
+```js
+cache.clear();
+```
-* [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)
+## About
-## Contributing
+<details>
+<summary><strong>Contributing</strong></summary>
-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](../../issues/new).
-Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/cache-base/issues/new).
+</details>
-## Building docs
+<details>
+<summary><strong>Running Tests</strong></summary>
-Generate readme and API documentation with [verb](https://github.com/verbose/verb):
+Running 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:
```sh
-$ npm install -g verb verb-readme-generator && verb
+$ npm install && npm test
```
-## Running tests
+</details>
+<details>
+<summary><strong>Building docs</strong></summary>
-Install dev dependencies:
+_(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.)_
+
+To generate the readme, run the following command:
```sh
-$ npm install -d && npm test
+$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
-## Author
+</details>
+
+### 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://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`.")
+* [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 "Use property paths (`a.b.c`) to get a nested value from an object.")
+* [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.")
+* [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.")
+* [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.")
+* [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.")
+
+### Contributors
+
+| **Commits** | **Contributor** |
+| --- | --- |
+| 64 | [jonschlinkert](https://github.com/jonschlinkert) |
+| 2 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
+
+### Author
**Jon Schlinkert**
+* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert)
* [github/jonschlinkert](https://github.com/jonschlinkert)
-* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
-## License
+### License
-Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
-Released under the [MIT license](https://github.com/jonschlinkert/cache-base/blob/master/LICENSE).
+Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
+Released under the [MIT License](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
+_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on December 19, 2017._
\ No newline at end of file
diff --git a/index.js b/index.js
index 473f5f3..ab859db 100644
--- a/index.js
+++ b/index.js
@@ -1,245 +1,236 @@
'use strict';
-var utils = require('./utils');
+const isObject = require('isobject');
+const Emitter = require('@sellside/emitter');
+const visit = require('collection-visit');
+const union = require('union-value');
+const del = require('unset-value');
+const get = require('get-value');
+const set = require('set-value');
/**
- * Create a `Cache` constructor that when instantiated will
- * store values on the given `prop`.
+ * Create a new `Cache`. Internally the `Cache` constructor is created using
+ * the `namespace` function, with `cache` defined as the storage object.
*
* ```js
- * var Cache = require('cache-base').namespace('data');
- * var cache = new Cache();
- *
- * cache.set('foo', 'bar');
- * //=> {data: {foo: 'bar'}}
+ * const cache = new Cache();
* ```
- * @param {String} `prop` The property name to use for storing values.
- * @return {Function} Returns a custom `Cache` constructor
+ * @param {Object} `cache` Optionally pass an object to initialize with.
+ * @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
- */
+class Cache extends Emitter {
+ constructor(prop, cache) {
+ super();
- function Cache(cache) {
- if (prop) {
- this[prop] = {};
+ if (typeof prop === 'string') {
+ Reflect.defineProperty(this, 'prop', { value: prop });
+ this[this.prop] = {};
+ } else {
+ cache = prop || cache;
}
+
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) {
+ * cache.on('set', function(key, val) {
* // do something when `set` is emitted
* });
*
- * app.set(key, value);
+ * cache.set(key, value);
*
* // also takes an object or array
- * app.set({name: 'Halle'});
- * app.set([{foo: 'bar'}, {baz: 'quux'}]);
- * console.log(app);
+ * cache.set({name: 'Halle'});
+ * cache.set([{foo: 'bar'}, {baz: 'quux'}]);
+ * console.log(cache);
* //=> {name: 'Halle', foo: 'bar', baz: 'quux'}
* ```
*
* @name .set
* @emits `set` with `key` and `value` as arguments.
- * @param {String} `key`
+ * @param {String|Array} `key` The name of the property to set. Dot-notation or an array of object path segments may be used.
* @param {any} `value`
* @return {Object} Returns the instance for chaining.
* @api public
*/
- Cache.prototype.set = function(key, val) {
+ set(key, val) {
if (Array.isArray(key) && arguments.length === 2) {
- key = utils.toPath(key);
+ key = key.join('.');
}
- 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(this.prop ? this[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'));
+ * cache.union('a.b', ['foo']);
+ * cache.union('a.b', ['bar']);
+ * console.log(cache.get('a'));
* //=> {b: ['foo', 'bar']}
* ```
* @name .union
- * @param {String} `key`
+ * @param {String|Array} `key` The name of the property to union. Dot-notation or an array of object path segments may be used.
* @param {any} `value`
* @return {Object} Returns the instance for chaining.
* @api public
*/
- Cache.prototype.union = function(key, val) {
+ union(key, val) {
if (Array.isArray(key) && arguments.length === 2) {
- key = utils.toPath(key);
+ key = key.join('.');
}
- var ctx = prop ? this[prop] : this;
- utils.union(ctx, key, utils.arrayify(val));
+ const ctx = this.prop ? this[this.prop] : this;
+ union(ctx, key, val);
this.emit('union', val);
return this;
- };
+ }
/**
- * Return the value of `key`. Dot notation may be used
- * to get [nested property values][get-value].
+ * 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'}
+ * cache.set('a.b.c', 'd');
+ * cache.get('a.b');
+ * //=> { c: 'd' }
*
- * app.get(['a', 'b']);
- * //=> {c: 'd'}
+ * cache.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.
+ * @param {String|Array} `key` The name of the property to get. Dot-notation or an array of object path segments may be used.
* @return {any} Returns the value of `key`
* @api public
*/
- Cache.prototype.get = function(key) {
- key = utils.toPath(arguments);
+ get(key) {
+ if (Array.isArray(key)) key = key.join('.');
+ if (arguments.length > 1) {
+ key = [].concat.apply([], arguments).join('.');
+ }
- var ctx = prop ? this[prop] : this;
- var val = utils.get(ctx, key);
+ const ctx = this.prop ? this[this.prop] : this;
+ const val = get(ctx, key);
this.emit('get', key, val);
return val;
- };
+ }
/**
- * Return true if app has a stored value for `key`,
+ * Return true if cache has a stored value for `key`,
* false only if value is `undefined`.
*
* ```js
- * app.set('foo', 'bar');
- * app.has('foo');
+ * cache.set('foo', 'bar');
+ * cache.has('foo');
* //=> true
* ```
*
* @name .has
* @emits `has` with `key` and true or false as arguments.
- * @param {String} `key`
+ * @param {String|Array} `key` The name of the property to check. Dot-notation or an array of object path segments may be used.
* @return {Boolean}
* @api public
*/
- Cache.prototype.has = function(key) {
- key = utils.toPath(arguments);
+ has(key) {
+ if (Array.isArray(key)) key = key.join('.');
- var ctx = prop ? this[prop] : this;
- var val = utils.get(ctx, key);
+ const ctx = this.prop ? this[this.prop] : this;
+ const val = get(ctx, key);
- var has = typeof val !== 'undefined';
+ const has = typeof val !== 'undefined';
this.emit('has', key, has);
return has;
- };
+ }
/**
* Delete one or more properties from the instance.
*
* ```js
- * app.del(); // delete all
+ * cache.del(); // delete all
* // or
- * app.del('foo');
+ * cache.del('foo');
* // or
- * app.del(['foo', 'bar']);
+ * cache.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.
+ * @param {String|Array} `key` The name of the property to delete. Dot-notation or an array of object path segments may be used.
* @return {Object} Returns the instance for chaining.
* @api public
*/
- Cache.prototype.del = function(key) {
+ del(key) {
if (Array.isArray(key)) {
this.visit('del', key);
} else {
- utils.del(prop ? this[prop] : this, key);
+ del(this.prop ? this[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 {String|Array} `key` The name of the method to visit. Dot-notation or an array of object path segments may be used.
* @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);
+ visit(key, val) {
+ if (Array.isArray(key)) {
+ key = key.join('.');
+ }
+ visit(this, key, val);
return this;
- };
+ }
+
+ /**
+ * Reset the entire cache to an empty object.
+ *
+ * ```js
+ * cache.clear();
+ * ```
+ * @api public
+ */
- return Cache;
+ clear() {
+ if (this.prop) {
+ this[this.prop] = {};
+ } else {
+ for (const key of Object.keys(this)) {
+ delete this[key];
+ }
+ }
+ }
}
/**
* Expose `Cache`
*/
-module.exports = namespace();
-
-/**
- * Expose `Cache.namespace`
- */
-
-module.exports.namespace = namespace;
+module.exports = Cache;
diff --git a/package.json b/package.json
index d53072b..93f2daa 100644
--- a/package.json
+++ b/package.json
@@ -1,17 +1,20 @@
{
"name": "cache-base",
"description": "Basic object cache with `get`, `set`, `del`, and `has` methods for node.js/javascript projects.",
- "version": "0.8.4",
+ "version": "2.0.2",
"homepage": "https://github.com/jonschlinkert/cache-base",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
+ "contributors": [
+ "Jon Schlinkert (http://twitter.com/jonschlinkert)",
+ "(https://github.com/wtgtybhertgeghgtwtg)"
+ ],
"repository": "jonschlinkert/cache-base",
"bugs": {
"url": "https://github.com/jonschlinkert/cache-base/issues"
},
"license": "MIT",
"files": [
- "index.js",
- "utils.js"
+ "index.js"
],
"main": "index.js",
"engines": {
@@ -21,22 +24,20 @@
"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"
+ "@sellside/emitter": "^1.2.1",
+ "collection-visit": "^1.0.0",
+ "get-value": "^2.0.6",
+ "isobject": "^3.0.1",
+ "set-value": "^2.0.0",
+ "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.5.3"
},
"keywords": [
+ "base",
"cache",
"config",
"data",
diff --git a/test/test.js b/test/test.js
index 2619ad8..422c541 100644
--- a/test/test.js
+++ b/test/test.js
@@ -84,6 +84,13 @@ describe('cache-base', function() {
assert.deepEqual(app.get('a'), ['b', 'c', 'd']);
});
+ it('should union strings and arrays', function() {
+ app.union('a', 'a');
+ app.union('a', ['b']);
+ app.union('a', ['c', 'd']);
+ assert.deepEqual(app.get('a'), ['a', 'b', 'c', 'd']);
+ });
+
it('should union nested string values', function() {
app.union('a.b', 'b');
app.union('a.b', 'c');
@@ -121,7 +128,7 @@ describe('cache-base', function() {
assert.equal(app.get('c').d, 'e');
});
- it('should return `this` for chaining', function() {
+ it('should be chainable', function() {
assert.equal(app.set('a', 'b'), app);
app
.set('aa', 'bb')
@@ -188,9 +195,7 @@ describe('events', function() {
describe('get', function() {
it('should emit a get event', function(cb) {
- app.on('get', function(key) {
- cb();
- });
+ app.on('get', () => cb());
app.get('a');
});
@@ -215,9 +220,7 @@ describe('events', function() {
describe('has', function() {
it('should emit a has event', function(cb) {
- app.on('has', function(key) {
- cb();
- });
+ app.on('has', () => cb());
app.has('a');
});
@@ -242,9 +245,7 @@ describe('events', function() {
describe('del', function() {
it('should emit a del event', function(cb) {
- app.on('del', function(key) {
- cb();
- });
+ app.on('del', () => cb());
app.del('a');
});
@@ -277,9 +278,8 @@ describe('events', function() {
describe('namespace', function() {
beforeEach(function() {
- cache = require('..');
- Cache = cache.namespace('data');
- app = new Cache();
+ Cache = require('..');
+ app = new Cache('data');
});
describe('constructor:', function() {
@@ -288,7 +288,7 @@ describe('namespace', function() {
});
it('should set ', function() {
- var app = new Cache({
+ var app = new Cache('data', {
one: 1,
two: 2
});
@@ -302,6 +302,7 @@ describe('namespace', function() {
it('should set a new property with the given value', function() {
app.set('one', 1);
assert.equal(app.get('one'), 1);
+ assert.equal(app.data.one, 1);
});
});
@@ -309,11 +310,13 @@ describe('namespace', function() {
it('should update an existing property with the given value', function() {
app.set('one', 2);
assert.equal(app.get('one'), 2);
+ assert.equal(app.data.one, 2);
});
it('should get the given property', function() {
app.set('a', 'b');
assert.equal(app.get('a'), 'b');
+ assert.equal(app.data.a, 'b');
});
});
});
@@ -322,9 +325,10 @@ describe('namespace', function() {
it('should set a value', function() {
app.set('a', 'b');
assert.equal(app.get('a'), 'b');
+ assert.equal(app.data.a, 'b');
});
- it('should set properties on the `cache` object.', function() {
+ it('should set properties on the `data` object.', function() {
app.set('a', 'b');
assert.equal(app.data.a, 'b');
});
@@ -335,24 +339,29 @@ describe('namespace', function() {
assert.equal(app.get('x'), 'y');
});
- it('should set nested properties on the `cache` object.', function() {
+ it('should set nested properties on the `data` object.', function() {
app.set('c', {d: 'e'});
assert.equal(app.get('c').d, 'e');
});
- it('should return `this` for chaining', function() {
+ it('should be chainable', 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');
+
+ assert.equal(app.data.aa, 'bb');
+ assert.equal(app.data.bb, 'cc');
+ assert.equal(app.data.cc, 'dd');
});
it('should return undefined when not set', function() {
- assert.equal(app.set('a', undefined), app);
+ assert.equal(app.set('sfsfsdfs', undefined), app);
});
});
@@ -364,6 +373,7 @@ describe('namespace', function() {
it('should otherwise return the value', function() {
app.set('a', 'b');
assert.equal(app.get('a'), 'b');
+ assert.equal(app.data.a, 'b');
});
});
-});
\ No newline at end of file
+});
diff --git a/utils.js b/utils.js
deleted file mode 100644
index 5b1740a..0000000
--- a/utils.js
+++ /dev/null
@@ -1,38 +0,0 @@
-'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