@codegouvfr/react-dsfr
Version:
French State Design System React integration library
20 lines • 668 B
JavaScript
export function memoize(fn, options) {
const cache = new Map();
const { argsLength = fn.length, max = Infinity } = options !== null && options !== void 0 ? options : {};
return ((...args) => {
const key = JSON.stringify(args.slice(0, argsLength).join("-sIs9sAslOdeWlEdIos3-"));
if (cache.has(key)) {
return cache.get(key);
}
if (max === cache.size) {
for (const key of cache.keys()) {
cache.delete(key);
break;
}
}
const value = fn(...args);
cache.set(key, value);
return value;
});
}
//# sourceMappingURL=memoize.js.map