UNPKG

@nestjs/passport

Version:

Nest - modern, fast, powerful node.js web framework (@passport)

16 lines (15 loc) 371 B
const defaultKey = 'default'; export function memoize(fn) { const cache = {}; return (...args) => { const n = args[0] || defaultKey; if (n in cache) { return cache[n]; } else { const result = fn(n === defaultKey ? undefined : n); cache[n] = result; return result; } }; }