@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
32 lines • 1.09 kB
TypeScript
type DebounceOptions = {
leading?: boolean;
trailing?: boolean;
maxWait?: number;
};
/**
* @callback DebounceCallback
* @template T
* @param {...any} args - Arguments to pass to the debounced function.
* @returns {void}
*/
/**
* @typedef {Object} DebounceOptions
* @property {boolean} [leading]
* @property {boolean} [trailing]
* @property {number} [maxWait]
*/
/**
* Creates a debounced version of a function.
* @template T
* @param {DebounceCallback} callback - The function to debounce.
* @param {number} [wait=300] - The debounce wait time in milliseconds.
* @param {DebounceOptions} [options] - Debounce configuration.
* @returns {((...args: Parameters<T>) => void) & { cancel: () => void; flush: () => void }} The debounced function.
* @throws {Error} If both leading and trailing are false.
*/
export default function debounce<T extends (...args: any[]) => void>(callback: T, wait?: number, options?: DebounceOptions): ((...args: Parameters<T>) => void) & {
cancel: () => void;
flush: () => void;
};
export {};
//# sourceMappingURL=debounce.d.ts.map