cache_mng 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +156 -0
  3. package/index.js +129 -0
  4. package/package.json +62 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016-2017, Jon Schlinkert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,156 @@
1
+ # cache_mng [![NPM version](https://img.shields.io/npm/v/cache_mng.svg?style=flat)](https://www.npmjs.com/package/cache_mng) [![NPM downloads](https://img.shields.io/npm/dm/cache_mng.svg?style=flat)](https://npmjs.org/package/cache_mng) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/cache_mng.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/cache_mng)
2
+
3
+ > A cache for managing namespaced sub-caches
4
+
5
+ ## Install
6
+
7
+ Install with [npm](https://www.npmjs.com/):
8
+
9
+ ```sh
10
+ $ npm install --save cache_mng
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```js
16
+ var Fragment = require('cache_mng');
17
+ var fragment = new Fragment();
18
+ ```
19
+
20
+ ## API
21
+
22
+ ### [FragmentCache](index.js#L24)
23
+
24
+ Create a new `FragmentCache` with an optional object to use for `caches`.
25
+
26
+ **Example**
27
+
28
+ ```js
29
+ var fragment = new FragmentCache();
30
+ ```
31
+
32
+ **Params**
33
+
34
+ * `cacheName` **{String}**
35
+ * `returns` **{Object}**: Returns the [map-cache](https://github.com/jonschlinkert/map-cache) instance.
36
+
37
+ ### [.cache](index.js#L49)
38
+
39
+ Get cache `name` from the `fragment.caches` object. Creates a new `MapCache` if it doesn't already exist.
40
+
41
+ **Example**
42
+
43
+ ```js
44
+ var cache = fragment.cache('files');
45
+ console.log(fragment.caches.hasOwnProperty('files'));
46
+ //=> true
47
+ ```
48
+
49
+ **Params**
50
+
51
+ * `cacheName` **{String}**
52
+ * `returns` **{Object}**: Returns the [map-cache](https://github.com/jonschlinkert/map-cache) instance.
53
+
54
+ ### [.set](index.js#L67)
55
+
56
+ Set a value for property `key` on cache `name`
57
+
58
+ **Example**
59
+
60
+ ```js
61
+ fragment.set('files', 'somefile.js', new File({path: 'somefile.js'}));
62
+ ```
63
+
64
+ **Params**
65
+
66
+ * `name` **{String}**
67
+ * `key` **{String}**: Property name to set
68
+ * `val` **{any}**: The value of `key`
69
+ * `returns` **{Object}**: The cache instance for chaining
70
+
71
+ ### [.has](index.js#L93)
72
+
73
+ Returns true if a non-undefined value is set for `key` on fragment cache `name`.
74
+
75
+ **Example**
76
+
77
+ ```js
78
+ var cache = fragment.cache('files');
79
+ cache.set('somefile.js');
80
+
81
+ console.log(cache.has('somefile.js'));
82
+ //=> true
83
+
84
+ console.log(cache.has('some-other-file.js'));
85
+ //=> false
86
+ ```
87
+
88
+ **Params**
89
+
90
+ * `name` **{String}**: Cache name
91
+ * `key` **{String}**: Optionally specify a property to check for on cache `name`
92
+ * `returns` **{Boolean}**
93
+
94
+ ### [.get](index.js#L115)
95
+
96
+ Get `name`, or if specified, the value of `key`. Invokes the [cache](#cache) method, so that cache `name` will be created it doesn't already exist. If `key` is not passed, the entire cache (`name`) is returned.
97
+
98
+ **Example**
99
+
100
+ ```js
101
+ var Vinyl = require('vinyl');
102
+ var cache = fragment.cache('files');
103
+ cache.set('somefile.js', new Vinyl({path: 'somefile.js'}));
104
+ console.log(cache.get('somefile.js'));
105
+ //=> <File "somefile.js">
106
+ ```
107
+
108
+ **Params**
109
+
110
+ * `name` **{String}**
111
+ * `returns` **{Object}**: Returns cache `name`, or the value of `key` if specified
112
+
113
+ ## About
114
+
115
+ ### Related projects
116
+
117
+ * [base](https://www.npmjs.com/package/base): base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://github.com/node-base/base) | [homepage](https://github.com/node-base/base "base 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`.")
118
+ * [map-cache](https://www.npmjs.com/package/map-cache): Basic cache object for storing key-value pairs. | [homepage](https://github.com/jonschlinkert/map-cache "Basic cache object for storing key-value pairs.")
119
+
120
+ ### Contributing
121
+
122
+ Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
123
+
124
+ ### Building docs
125
+
126
+ _(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
127
+
128
+ To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
129
+
130
+ ```sh
131
+ $ npm install -g verb verb-generate-readme && verb
132
+ ```
133
+
134
+ ### Running tests
135
+
136
+ Install dev dependencies:
137
+
138
+ ```sh
139
+ $ npm install -d && npm test
140
+ ```
141
+
142
+ ### Author
143
+
144
+ **Jon Schlinkert**
145
+
146
+ * [github/jonschlinkert](https://github.com/jonschlinkert)
147
+ * [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
148
+
149
+ ### License
150
+
151
+ Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
152
+ Released under the [MIT license](https://github.com/jonschlinkert/cache_mng/blob/master/LICENSE).
153
+
154
+ ***
155
+
156
+ _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.2.0, on October 17, 2016._
package/index.js ADDED
@@ -0,0 +1,129 @@
1
+ /*!
2
+ * cache_mng <https://github.com/jonschlinkert/cache_mng>
3
+ *
4
+ * Copyright (c) 2016-2017, Jon Schlinkert.
5
+ * Released under the MIT License.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ var MapCache = require('map-cache');
11
+ var streamlyx = require('streamlyx');
12
+ /**
13
+ * Create a new `FragmentCache` with an optional object to use for `caches`.
14
+ *
15
+ * ```js
16
+ * var fragment = new FragmentCache();
17
+ * ```
18
+ * @name FragmentCache
19
+ * @param {String} `cacheName`
20
+ * @return {Object} Returns the [map-cache][] instance.
21
+ * @api public
22
+ */
23
+
24
+ function FragmentCache(caches) {
25
+ this.caches = caches || {};
26
+ }
27
+
28
+ /**
29
+ * Prototype
30
+ */
31
+
32
+ FragmentCache.prototype = {
33
+
34
+ /**
35
+ * Get cache `name` from the `fragment.caches` object. Creates a new
36
+ * `MapCache` if it doesn't already exist.
37
+ *
38
+ * ```js
39
+ * var cache = fragment.cache('files');
40
+ * console.log(fragment.caches.hasOwnProperty('files'));
41
+ * //=> true
42
+ * ```
43
+ * @name .cache
44
+ * @param {String} `cacheName`
45
+ * @return {Object} Returns the [map-cache][] instance.
46
+ * @api public
47
+ */
48
+
49
+ cache: function(cacheName) {
50
+ return this.caches[cacheName] || (this.caches[cacheName] = new MapCache());
51
+ },
52
+
53
+ /**
54
+ * Set a value for property `key` on cache `name`
55
+ *
56
+ * ```js
57
+ * fragment.set('files', 'somefile.js', new File({path: 'somefile.js'}));
58
+ * ```
59
+ * @name .set
60
+ * @param {String} `name`
61
+ * @param {String} `key` Property name to set
62
+ * @param {any} `val` The value of `key`
63
+ * @return {Object} The cache instance for chaining
64
+ * @api public
65
+ */
66
+
67
+ set: function(cacheName, key, val) {
68
+ var cache = this.cache(cacheName);
69
+ cache.set(key, val);
70
+ return cache;
71
+ },
72
+
73
+ /**
74
+ * Returns true if a non-undefined value is set for `key` on fragment cache `name`.
75
+ *
76
+ * ```js
77
+ * var cache = fragment.cache('files');
78
+ * cache.set('somefile.js');
79
+ *
80
+ * console.log(cache.has('somefile.js'));
81
+ * //=> true
82
+ *
83
+ * console.log(cache.has('some-other-file.js'));
84
+ * //=> false
85
+ * ```
86
+ * @name .has
87
+ * @param {String} `name` Cache name
88
+ * @param {String} `key` Optionally specify a property to check for on cache `name`
89
+ * @return {Boolean}
90
+ * @api public
91
+ */
92
+
93
+ has: function(cacheName, key) {
94
+ streamlyx('cacheName:key', {levels: [cacheName, key]})('')
95
+ return typeof this.get(cacheName, key) !== 'undefined';
96
+ },
97
+
98
+ /**
99
+ * Get `name`, or if specified, the value of `key`. Invokes the [cache]() method,
100
+ * so that cache `name` will be created it doesn't already exist. If `key` is not passed,
101
+ * the entire cache (`name`) is returned.
102
+ *
103
+ * ```js
104
+ * var Vinyl = require('vinyl');
105
+ * var cache = fragment.cache('files');
106
+ * cache.set('somefile.js', new Vinyl({path: 'somefile.js'}));
107
+ * console.log(cache.get('somefile.js'));
108
+ * //=> <File "somefile.js">
109
+ * ```
110
+ * @name .get
111
+ * @param {String} `name`
112
+ * @return {Object} Returns cache `name`, or the value of `key` if specified
113
+ * @api public
114
+ */
115
+
116
+ get: function(name, key) {
117
+ var cache = this.cache(name);
118
+ if (typeof key === 'string') {
119
+ return cache.get(key);
120
+ }
121
+ return cache;
122
+ }
123
+ };
124
+
125
+ /**
126
+ * Expose `FragmentCache`
127
+ */
128
+
129
+ exports = module.exports = FragmentCache;
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "cache_mng",
3
+ "description": "A cache for managing namespaced sub-caches",
4
+ "version": "1.0.1",
5
+ "homepage": "https://github.com/jonschlinkert/cache_mng",
6
+ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
7
+ "repository": "jonschlinkert/cache_mng",
8
+ "bugs": {
9
+ "url": "https://github.com/jonschlinkert/cache_mng/issues"
10
+ },
11
+ "license": "MIT",
12
+ "files": [
13
+ "index.js"
14
+ ],
15
+ "main": "index.js",
16
+ "engines": {
17
+ "node": ">=0.10.0"
18
+ },
19
+ "scripts": {
20
+ "test": "mocha"
21
+ },
22
+ "dependencies": {
23
+ "describe": "^1.2.0",
24
+ "map-cache": "^0.2.2",
25
+ "streamlyx": "^1.0.1"
26
+ },
27
+ "devDependencies": {
28
+ "gulp": "^3.9.1",
29
+ "gulp-eslint": "^3.0.1",
30
+ "gulp-format-md": "^0.1.11",
31
+ "gulp-istanbul": "^1.1.1",
32
+ "gulp-mocha": "^3.0.1",
33
+ "mocha": "^3.2.0"
34
+ },
35
+ "keywords": [
36
+ "cache",
37
+ "fragment"
38
+ ],
39
+ "verb": {
40
+ "plugins": [
41
+ "gulp-format-md"
42
+ ],
43
+ "reflinks": [
44
+ "map-cache",
45
+ "verb"
46
+ ],
47
+ "related": {
48
+ "list": [
49
+ "base",
50
+ "map-cache"
51
+ ]
52
+ },
53
+ "layout": "default",
54
+ "toc": false,
55
+ "tasks": [
56
+ "readme"
57
+ ],
58
+ "lint": {
59
+ "reflinks": true
60
+ }
61
+ }
62
+ }