This repository has been archived on 2026-03-28. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
StasisWarden-Legacy/node_modules/es-toolkit/dist/function/memoize.js
T

21 lines
543 B
JavaScript

'use strict';
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
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;
}
exports.memoize = memoize;