@utilify/function
Version:
These utilities help with tasks such as debouncing, throttling, function composition, and managing async behavior, making it easier to handle function flow and optimize performance.
38 lines (19 loc) • 1.77 kB
TypeScript
declare function benchmark(callback: () => void | Promise<void>, iterations?: number): Promise<number>;
declare function debounce(callback: (...args: any[]) => void, delay?: number): (...args: any[]) => void;
declare function memo(callback: (...args: any[]) => any, cacheTimeout?: number): (...args: any[]) => any;
declare function throttle(callback: (...args: any[]) => void, wait?: number): (...args: any[]) => void;
declare function fallback<T, U = T>(callback: () => T, fallback: () => U): T | U;
declare function lock(callback: (...args: any[]) => Promise<void>): (...args: any[]) => void;
declare function noop(): void;
declare function once<T>(callback: (...args: any[]) => T): (...args: any[]) => T;
declare function partialLeft<T>(callback: (...args: any[]) => T, ...partial: any[]): (...args: any[]) => T;
declare function rate(callback: (...args: any[]) => void, limit: number, interval: number): (...args: any[]) => boolean;
declare function sleep(timeout: number): Promise<void>;
declare function guard<T, U = T>(validator: (...args: T[]) => boolean, callback: (...args: T[]) => U, fallback: (...args: T[]) => U): (...args: T[]) => U;
declare function pipe<T>(...callbacks: ((value: T) => T)[]): (value: T) => T;
declare function compose<T>(...callbacks: ((value: T) => T)[]): (value: T) => T;
declare function defer(callback: () => void): void;
declare function identity<T>(value: T): T;
declare function parallel(...callbacks: (() => Promise<any>)[]): Promise<any[]>;
declare function partialRight<T>(callback: (...args: any[]) => T, ...partial: any[]): (...args: any[]) => T;
export { benchmark, compose, debounce, defer, fallback, guard, identity, lock, memo, noop, once, parallel, partialLeft, partialRight, pipe, rate, sleep, throttle };