import type { AnyFunction } from './types'; /** Resolves after `ms`; an aborted `signal` rejects with its reason and clears the timer. */ export declare function sleep(ms: number, { signal }?: { signal?: AbortSignal | undefined; }): Promise; export declare function delay(ms: number, callback?: T, ...args: Parameters): Promise>; export interface DebounceOptions { /** Run on the first call of a burst. Default `false` for `debounce`, `true` for `throttle`. */ leading?: boolean; /** Run once the burst is over, with the last call's arguments. Default `true` for `debounce`, `false` for `throttle`. */ trailing?: boolean; /** Longest a call waits while calls keep coming, at least `delay`. Defaults to `delay` for `throttle`. */ maxWait?: number; } export interface Debounced { (...args: Parameters): void; /** Drops the pending call. */ cancel: () => void; /** Runs the pending call now, if any. */ flush: () => void; } /** Runs `func` once calls stop for `delay`; `leading`, `trailing` and `maxWait` pick which edges of a burst run it. */ export declare function debounce(func: T, delay: number, { leading, trailing, maxWait }?: DebounceOptions): Debounced; export interface CoalesceOptions { /** Wait from the first trigger of a burst before running, never pushed back by later triggers. */ delay: number; /** Gets a failed run's error. Default `console.error`. */ onError?: (error: unknown) => void; } /** Runs an async task at most once at a time: a burst of triggers within `delay` runs it once, triggers during a run queue one more, a failure goes to `onError`. */ export declare function coalesce(task: () => Promise, options: CoalesceOptions): () => void; export declare function coalesce(task: () => Promise, delay: number, onError?: (error: unknown) => void): () => void; /** Returns a runner starting each task it is given once the ones given before have settled, in call order; a failure rejects only its own call. */ export declare function createMutex(): (task: () => Promise) => Promise; /** Returns a gate resolving each call at least `interval` after the one before, slots reserved at call time so concurrent callers spread out; an aborted `signal` rejects only its own wait, and its slot stays taken. */ export declare function createRateLimiter(interval: number): (options?: { signal?: AbortSignal | undefined; }) => Promise; /** Runs `func` at most once per `delay`; by default on the first call of each window, dropping the rest. */ export declare function throttle(func: T, delay: number, { leading, trailing, maxWait }?: DebounceOptions): Debounced; export declare function once(func: T): ((...args: Parameters) => ReturnType); /** Returns its argument unchanged. */ export declare function identity(value: T): T; /** Does nothing. Useful as a default callback. */ export declare function noop(): void; /** Runs `fn` on `value` for its side effect, then returns `value`. Handy inside a `pipe`. */ export declare function tap(value: T, fn: (value: T) => void): T; /** Returns a predicate that negates `predicate`. */ export declare function negate(predicate: (...args: T) => boolean): ((...args: T) => boolean); /** Pre-applies leading `preset` arguments to `func`. */ export declare function partial

(func: (...args: [...P, ...A]) => R, ...preset: P): ((...args: A) => R); /** Compose functions left-to-right: `pipe(f, g)(x)` is `g(f(x))`. */ export declare function pipe(fn1: (...a: A) => B): (...a: A) => B; export declare function pipe(fn1: (...a: A) => B, fn2: (b: B) => C): (...a: A) => C; export declare function pipe(fn1: (...a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D): (...a: A) => D; export declare function pipe(fn1: (...a: A) => B, fn2: (b: B) => C, fn3: (c: C) => D, fn4: (d: D) => E): (...a: A) => E; export declare function pipe(...fns: (AnyFunction)[]): AnyFunction; /** Compose functions right-to-left: `compose(g, f)(x)` is `g(f(x))`. */ export declare function compose(fn1: (...a: A) => B): (...a: A) => B; export declare function compose(fn2: (b: B) => C, fn1: (...a: A) => B): (...a: A) => C; export declare function compose(fn3: (c: C) => D, fn2: (b: B) => C, fn1: (...a: A) => B): (...a: A) => D; export declare function compose(fn4: (d: D) => E, fn3: (c: C) => D, fn2: (b: B) => C, fn1: (...a: A) => B): (...a: A) => E; export declare function compose(...fns: (AnyFunction)[]): AnyFunction; /** Curry `func` so it can be called with arguments one (or several) at a time until `arity` is reached. */ export declare function curry(func: AnyFunction, arity?: number): (AnyFunction); export type Result = [error: undefined, value: T] | [error: E, value: undefined]; /** Run `func`, returning a `[error, value]` tuple instead of throwing. Awaits and catches promises too. */ export declare function tryCatch(func: () => Promise): Promise>; export declare function tryCatch(func: () => T): Result; //# sourceMappingURL=function.d.ts.map