1 declare namespace oneTime {
4 Throw an error when called more than once.
12 declare const oneTime: {
14 Ensure a function is only called once. When called multiple times it will return the return value from the first call.
16 @param fn - Function that should only be called once.
17 @returns A function that only calls `fn` once.
19 <ArgumentsType extends unknown[], ReturnType>(
20 fn: (...arguments: ArgumentsType) => ReturnType,
21 options?: oneTime.Options
22 ): (...arguments: ArgumentsType) => ReturnType;
25 Get the number of times `fn` has been called.
27 @param fn - Function to get call count from.
28 @returns A number representing how many times `fn` has been called.
32 import onetime = require('onetime');
34 const foo = onetime(() => {});
39 console.log(onetime.callCount(foo));
43 callCount(fn: (...arguments: any[]) => unknown): number;
45 // TODO: Remove this for the next major release
46 default: typeof oneTime;