UNPKG

@common-utilities/debounce

Version:

A basic implementation of the common utility function, Debounce 🏓

19 lines 593 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.debounce = void 0; /** * debounce 🏓 * --- * @description a basic implementation of debounce * @param fn a function callback * @param delay a number in milliseconds * @example debounce(fn, 100); */ const debounce = (fn, delay, timeout = 0) => (args) => { clearTimeout(timeout); // adds `as unknown as number` to ensure setTimeout returns a number // like window.setTimeout timeout = setTimeout(() => fn(args), delay); }; exports.debounce = debounce; //# sourceMappingURL=index.js.map