source: trip-planner-front/node_modules/map-cache/index.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*!
2 * map-cache <https://github.com/jonschlinkert/map-cache>
3 *
4 * Copyright (c) 2015, Jon Schlinkert.
5 * Licensed under the MIT License.
6 */
7
8'use strict';
9
10var hasOwn = Object.prototype.hasOwnProperty;
11
12/**
13 * Expose `MapCache`
14 */
15
16module.exports = MapCache;
17
18/**
19 * Creates a cache object to store key/value pairs.
20 *
21 * ```js
22 * var cache = new MapCache();
23 * ```
24 *
25 * @api public
26 */
27
28function MapCache(data) {
29 this.__data__ = data || {};
30}
31
32/**
33 * Adds `value` to `key` on the cache.
34 *
35 * ```js
36 * cache.set('foo', 'bar');
37 * ```
38 *
39 * @param {String} `key` The key of the value to cache.
40 * @param {*} `value` The value to cache.
41 * @returns {Object} Returns the `Cache` object for chaining.
42 * @api public
43 */
44
45MapCache.prototype.set = function mapSet(key, value) {
46 if (key !== '__proto__') {
47 this.__data__[key] = value;
48 }
49 return this;
50};
51
52/**
53 * Gets the cached value for `key`.
54 *
55 * ```js
56 * cache.get('foo');
57 * //=> 'bar'
58 * ```
59 *
60 * @param {String} `key` The key of the value to get.
61 * @returns {*} Returns the cached value.
62 * @api public
63 */
64
65MapCache.prototype.get = function mapGet(key) {
66 return key === '__proto__' ? undefined : this.__data__[key];
67};
68
69/**
70 * Checks if a cached value for `key` exists.
71 *
72 * ```js
73 * cache.has('foo');
74 * //=> true
75 * ```
76 *
77 * @param {String} `key` The key of the entry to check.
78 * @returns {Boolean} Returns `true` if an entry for `key` exists, else `false`.
79 * @api public
80 */
81
82MapCache.prototype.has = function mapHas(key) {
83 return key !== '__proto__' && hasOwn.call(this.__data__, key);
84};
85
86/**
87 * Removes `key` and its value from the cache.
88 *
89 * ```js
90 * cache.del('foo');
91 * ```
92 * @title .del
93 * @param {String} `key` The key of the value to remove.
94 * @returns {Boolean} Returns `true` if the entry was removed successfully, else `false`.
95 * @api public
96 */
97
98MapCache.prototype.del = function mapDelete(key) {
99 return this.has(key) && delete this.__data__[key];
100};
Note: See TracBrowser for help on using the repository browser.