UNPKG

@web3r/flowerkit

Version:

Tree-shakable JavaScript and TypeScript utility library for frontend/browser apps: DOM, events, arrays, objects, strings, date, JSON, and network helpers (ESM/CJS, SSR-friendly).

18 lines (17 loc) 877 B
export type TGetThrottledFnArgs = Parameters<typeof getThrottledFn>; export type TGetThrottledFnReturn = ReturnType<typeof getThrottledFn>; /** * Gets a throttled function with specific delay * @template {(...args: any[]) => any} T * @param {T} func function * @param {number} [delay=1000] delay in ms, 1000 by default * @returns {(...args: Parameters<T>) => void} * @throws {TypeError} getThrottledFn: func must be a function * @throws {TypeError} getThrottledFn: delay must be a non-negative finite number * @example * // How to implement function throttling? * const getDataFromAPI = () => Promise.resolve([]); * const getThrottledDataFromAPI = getThrottledFn(getDataFromAPI, 3000); * getThrottledDataFromAPI(); // => [] */ export declare const getThrottledFn: <T extends (...args: any[]) => any>(func: T, delay?: number) => ((...args: Parameters<T>) => void);