Files
HRM-System/node_modules/prettier-plugin-organize-imports/lib/memoize.js
2026-04-13 08:19:53 +08:00

24 lines
462 B
JavaScript

/**
* Simple memoization utility that only uses the first argument as cache key and has no memory limit.
*
* @template {(...args: any[]) => any} F
* @param {F} f
* @returns {F}
*/
module.exports.memoize = (f) => {
const cache = new Map();
// @ts-ignore
return function (cacheKey, ...rest) {
if (cache.has(cacheKey)) {
return cache.get(cacheKey);
}
const result = f(cacheKey, ...rest);
cache.set(cacheKey, result);
return result;
};
};