Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 14, 2023
1 parent 7d01295 commit 804c23c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,15 @@ export default function mem<
return fn;
}

if (typeof maxAge === 'number' && maxAge < 0) {
throw new TypeError('The `maxAge` option should not be a negative number.');
if (typeof maxAge === 'number') {
const maxSetIntervalValue = 2_147_483_647;
if (maxAge > maxSetIntervalValue) {
throw new TypeError(`The \`maxAge\` option cannot exceed ${maxSetIntervalValue}.`);
}

if (maxAge < 0) {
throw new TypeError('The `maxAge` option should not be a negative number.');
}
}

const memoized = function (this: any, ...arguments_: Parameters<FunctionToMemoize>): ReturnType<FunctionToMemoize> {
Expand Down Expand Up @@ -226,7 +233,7 @@ export function memClear(fn: AnyFunction): void {
throw new TypeError('The cache Map can\'t be cleared!');
}

cache.clear();
cache.clear?.();

for (const timer of cacheTimerStore.get(fn) ?? []) {
clearTimeout(timer);
Expand Down

0 comments on commit 804c23c

Please sign in to comment.