UNPKG

es-toolkit

Version:

A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.

21 lines (17 loc) 543 B
'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;