@stryke/helpers
Version:
A package containing miscellaneous helper functions that are used across many different Storm Software projects.
29 lines (28 loc) • 995 B
TypeScript
/**
* Creates a throttled function that only invokes the provided function at most once
* per every `throttleMs` milliseconds. Subsequent calls to the throttled function
* within the wait time will not trigger the execution of the original function.
*
* @example
* ```typescript
* const throttledFunction = throttle(() => {
* console.log('Function executed');
* }, 1000);
*
* // Will log 'Function executed' immediately
* throttledFunction();
*
* // Will not log anything as it is within the throttle time
* throttledFunction();
*
* // After 1 second
* setTimeout(() => {
* throttledFunction(); // Will log 'Function executed'
* }, 1000);
* ```
*
* @param func - The function to throttle.
* @param throttleMs - The number of milliseconds to throttle executions to.
* @returns A new throttled function that accepts the same parameters as the original function.
*/
export declare function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number): F;