source: node_modules/es-toolkit/dist/function/memoize.js@ ba17441

Last change on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 543 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5function memoize(fn, options = {}) {
6 const { cache = new Map(), getCacheKey } = options;
7 const memoizedFn = function (arg) {
8 const key = getCacheKey ? getCacheKey(arg) : arg;
9 if (cache.has(key)) {
10 return cache.get(key);
11 }
12 const result = fn.call(this, arg);
13 cache.set(key, result);
14 return result;
15 };
16 memoizedFn.cache = cache;
17 return memoizedFn;
18}
19
20exports.memoize = memoize;
Note: See TracBrowser for help on using the repository browser.