import type { MaybeAsync, NonNullableProperties, NullableKeysToOptional } from './utilityTypes.js'; export declare class TimeoutError extends Error { } export declare class WaitIntervalUntilCanceledError extends Error { } /** * Build promise that can be resolved/rejected manually outside of the promise's execution scope */ export declare const buildManualPromise: () => { promise: Promise; resolve: (value: T) => void; reject: (reason?: any) => void; }; export type ManualPromise = ReturnType>; export declare const isNullOrUndefined: (val: unknown) => val is null | undefined; export declare const wait: (ms: number) => Promise; export declare const waitIntervalUntil: (ms: number, predicate: () => boolean) => Promise & { cancel: () => void; }; /** * Not nullable type guard, useful in `.filter()` calls for proper TS typed * results */ export declare const isNonNullable: (v: V) => v is NonNullable; /** * Make the promise throw after enough time has passed. Useful for implementing timeout functionality in various flows. */ export declare const timeoutAt: (ms: number, optionalMessage?: string) => Promise; /** * Invoke and return fn(), but retry it up to n times if it throws */ export declare const retry: (fn: () => MaybeAsync, n: number, delayMs?: number | ((attempt: number, error: Error) => number)) => Promise; /** * For quickly profiling a function */ export declare const profile: (fn: () => MaybeAsync, label?: string, extra?: unknown) => Promise; /** * For quickly profiling a sync function */ export declare const profileSync: (fn: () => V, label?: string, extra?: unknown) => V; export declare const removeNullOrUndefinedKeys: >(obj: T) => NonNullableProperties>; export declare const coerceUndefinedValuesToNull: >(obj: T) => Record | null>; export declare const isArrayOf: (arr: unknown, guard: (v: unknown) => v is T) => arr is T[]; export declare const waitForever: () => Promise; /** * Returns true if only one of the arguments is truthy */ export declare const xor: (a: unknown, b: unknown) => boolean; /** * Shortcut for creating string key & value enums. Native TS Enums are problematic in many ways * (transform code, instead of just adding types; you cant put a string literal matching the enum value * in a variable typed as the enum, etc.) */ export declare const StringEnum: (args: T[]) => Readonly<{ [K in T]: K; }>; /** * Shortcut for (typeof StringEnum)[keyof typeof StringEnum] */ export type StringEnumValues> = { [K in keyof T]: T[K] extends string ? T[K] : never; }[keyof T]; /** * Get first non-undefined/null value, or undefined if none found */ export declare const firstDefinedValue: (...args: (T | undefined | null)[]) => T | undefined; //# sourceMappingURL=utility.d.ts.map