UNPKG

@utilify/core

Version:

Modern, strongly typed, and safe utility function library for JavaScript and TypeScript. Includes type checking, manipulation of arrays, objects, strings, dates, colors, numbers, regular expressions, and more. Compatible with Browser, Node.js, Deno, and B

41 lines 1.31 kB
type ThrottleOptions = { leading?: boolean; trailing?: boolean; maxWait?: number; }; interface ThrottledFunction<T extends (...args: any[]) => void> { (...args: Parameters<T>): void; cancel(): void; flush(): void; } /** * @callback ThrottleCallback * @template T * @param {...any} args - Arguments to pass to the throttled function. * @returns {void} */ /** * @typedef {Object} ThrottleOptions * @property {boolean} [leading] * @property {boolean} [trailing] * @property {number} [maxWait] */ /** * @template T * @typedef {Object} ThrottledFunction * @property {function(...args: Parameters<T>): void} [call] * @property {function(): void} cancel * @property {function(): void} flush */ /** * Creates a throttled version of a function. * @template T * @param {ThrottleCallback} callback - The function to throttle. * @param {number} wait - The wait time in milliseconds. * @param {ThrottleOptions} [options] - Throttle configuration. * @returns {ThrottledFunction<T>} The throttled function. * @throws {TypeError} If callback is not a function. */ export default function throttle<T extends (...args: any[]) => void>(callback: T, wait: number, { leading, trailing, maxWait, }?: ThrottleOptions): ThrottledFunction<T>; export {}; //# sourceMappingURL=throttle.d.ts.map