source: node_modules/es-toolkit/dist/function/memoize.mjs@ a762898

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

Added visualizations

  • Property mode set to 100644
File size: 447 bytes
Line 
1function memoize(fn, options = {}) {
2 const { cache = new Map(), getCacheKey } = options;
3 const memoizedFn = function (arg) {
4 const key = getCacheKey ? getCacheKey(arg) : arg;
5 if (cache.has(key)) {
6 return cache.get(key);
7 }
8 const result = fn.call(this, arg);
9 cache.set(key, result);
10 return result;
11 };
12 memoizedFn.cache = cache;
13 return memoizedFn;
14}
15
16export { memoize };
Note: See TracBrowser for help on using the repository browser.