UNPKG

@yeger/debounce

Version:

A tiny TypeScript library for debouncing functions.

18 lines (17 loc) 469 B
//#region src/index.ts /** * Debounce a callback with an optional delay. * @param cb - The callback that will be invoked. * @param delay - A delay after which the callback will be invoked. * @returns The debounced callback. */ function debounce(cb, delay) { let timeout; return (...args) => { if (timeout !== void 0) clearTimeout(timeout); timeout = setTimeout(() => cb(...args), delay); }; } //#endregion export { debounce }; //# sourceMappingURL=index.mjs.map