-declare namespace oneTime {
+declare namespace onetime {
interface Options {
/**
Throw an error when called more than once.
}
}
-declare const oneTime: {
+declare const onetime: {
/**
Ensure a function is only called once. When called multiple times it will return the return value from the first call.
@param fn - Function that should only be called once.
@returns A function that only calls `fn` once.
+
+ @example
+ ```
+ import onetime = require('onetime');
+
+ let i = 0;
+
+ const foo = onetime(() => ++i);
+
+ foo(); //=> 1
+ foo(); //=> 1
+ foo(); //=> 1
+
+ onetime.callCount(foo); //=> 3
+ ```
*/
<ArgumentsType extends unknown[], ReturnType>(
fn: (...arguments: ArgumentsType) => ReturnType,
- options?: oneTime.Options
+ options?: onetime.Options
): (...arguments: ArgumentsType) => ReturnType;
/**
callCount(fn: (...arguments: any[]) => unknown): number;
// TODO: Remove this for the next major release
- default: typeof oneTime;
+ default: typeof onetime;
};
-export = oneTime;
+export = onetime;