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.
21 import onetime = require('onetime');
25 const foo = onetime(() => ++i);
31 onetime.callCount(foo); //=> 3
34 <ArgumentsType extends unknown[], ReturnType>(
35 fn: (...arguments: ArgumentsType) => ReturnType,
36 options?: onetime.Options
37 ): (...arguments: ArgumentsType) => ReturnType;
40 Get the number of times `fn` has been called.
42 @param fn - Function to get call count from.
43 @returns A number representing how many times `fn` has been called.
47 import onetime = require('onetime');
49 const foo = onetime(() => {});
54 console.log(onetime.callCount(foo));
58 callCount(fn: (...arguments: any[]) => unknown): number;
60 // TODO: Remove this for the next major release
61 default: typeof onetime;