Files
cannaiq/frontend/node_modules/es-toolkit/dist/function/memoize.mjs
2025-11-28 19:45:44 -07:00

17 lines
447 B
JavaScript

function memoize(fn, options = {}) {
const { cache = new Map(), getCacheKey } = options;
const memoizedFn = function (arg) {
const key = getCacheKey ? getCacheKey(arg) : arg;
if (cache.has(key)) {
return cache.get(key);
}
const result = fn.call(this, arg);
cache.set(key, result);
return result;
};
memoizedFn.cache = cache;
return memoizedFn;
}
export { memoize };