diff options
author | Florian Dold <florian.dold@gmail.com> | 2019-03-27 21:01:33 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2019-03-27 21:01:33 +0100 |
commit | cc97a4dd2a967e1c2273bd5f4c5f49a5bf2e2585 (patch) | |
tree | 92c5d88706a6ffc654d1b133618d357890e7096b /node_modules/mem/index.js | |
parent | 3771b4d6b67b34c130f3a9a1a15f42deefdb2eda (diff) | |
download | wallet-core-cc97a4dd2a967e1c2273bd5f4c5f49a5bf2e2585.tar.xz |
remove node_modules
Diffstat (limited to 'node_modules/mem/index.js')
-rw-r--r-- | node_modules/mem/index.js | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/node_modules/mem/index.js b/node_modules/mem/index.js deleted file mode 100644 index aa5a07398..000000000 --- a/node_modules/mem/index.js +++ /dev/null @@ -1,55 +0,0 @@ -'use strict'; -const mimicFn = require('mimic-fn'); - -const cacheStore = new WeakMap(); - -const defaultCacheKey = function (x) { - if (arguments.length === 1 && (x === null || x === undefined || (typeof x !== 'function' && typeof x !== 'object'))) { - return x; - } - - return JSON.stringify(arguments); -}; - -module.exports = (fn, opts) => { - opts = Object.assign({ - cacheKey: defaultCacheKey, - cache: new Map() - }, opts); - - const memoized = function () { - const cache = cacheStore.get(memoized); - const key = opts.cacheKey.apply(null, arguments); - - if (cache.has(key)) { - const c = cache.get(key); - - if (typeof opts.maxAge !== 'number' || Date.now() < c.maxAge) { - return c.data; - } - } - - const ret = fn.apply(null, arguments); - - cache.set(key, { - data: ret, - maxAge: Date.now() + (opts.maxAge || 0) - }); - - return ret; - }; - - mimicFn(memoized, fn); - - cacheStore.set(memoized, opts.cache); - - return memoized; -}; - -module.exports.clear = fn => { - const cache = cacheStore.get(fn); - - if (cache && typeof cache.clear === 'function') { - cache.clear(); - } -}; |