/** * Miscellaneous utility helpers. * * @module bquery/core/utils/misc */ /** * Creates a stable unique ID for DOM usage. * * @param prefix - Optional prefix for the ID (default: 'bQuery') * @returns A unique identifier string * * @example * ```ts * const id = uid('modal'); // 'modal_x7k2m9p' * ``` */ export declare function uid(prefix?: string): string; /** * Delays execution for a specified number of milliseconds. * * @param ms - Milliseconds to delay * @returns A promise that resolves after the delay * * @example * ```ts * await sleep(1000); // Wait 1 second * console.log('Done!'); * ``` */ export declare function sleep(ms: number): Promise; /** * Safely parses a JSON string, returning a default value on error. * * @template T - The expected type of the parsed value * @param json - The JSON string to parse * @param fallback - The default value if parsing fails * @returns The parsed value or the fallback * * @example * ```ts * parseJson('{"name":"bQuery"}', {}); // { name: 'bQuery' } * parseJson('invalid', {}); // {} * ``` */ export declare function parseJson(json: string, fallback: T): T; /** * Checks for emptiness across common value types. * * @param value - The value to check * @returns True if the value is empty (null, undefined, empty string, empty array, or empty object) * * @example * ```ts * isEmpty(''); // true * isEmpty([]); // true * isEmpty({}); // true * isEmpty(null); // true * isEmpty('hello'); // false * isEmpty([1, 2]); // false * ``` */ export declare function isEmpty(value: unknown): boolean; /** * Returns an RFC 4122 v4 UUID. Uses `crypto.randomUUID()` when available, * falling back to `crypto.getRandomValues()`-backed assembly, and finally * to a `Math.random()`-based variant. The fallback path is **not** * cryptographically secure. */ export declare function uuid(): string; /** Tuple returned by {@link tryCatch}. */ export type TryCatchResult = [E, undefined] | [null, T]; /** * Runs a synchronous or asynchronous function and returns a Go-style * `[error, value]` tuple instead of throwing. The synchronous result * variant returns the tuple directly; the async variant returns a Promise. * Synchronous throws from Promise-typed callbacks still remain await/then-compatible. * * @example * ```ts * const [err, value] = tryCatch(() => JSON.parse(text)); * const [aErr, data] = await tryCatch(() => fetch('/api').then((r) => r.json())); * ``` */ export declare function tryCatch(fn: () => Promise): Promise>; export declare function tryCatch(fn: () => T): TryCatchResult; /** * Invokes `fn(i)` `n` times and returns the collected results. * * @example * ```ts * times(3, (i) => i * 2); // [0, 2, 4] * ``` */ export declare function times(n: number, fn: (index: number) => T): T[]; /** Options for {@link pollUntil}. */ export interface PollUntilOptions { /** Interval between polls in ms (default: 50). */ interval?: number; /** Total timeout in ms; rejects when exceeded (default: 5000). */ timeout?: number; /** Optional AbortSignal. */ signal?: AbortSignal; } /** * Polls `predicate()` on a fixed interval until it returns a truthy value, * resolving with that value. Rejects on timeout or abort. * * Distinct from the reactive `polling()` helper — this is a small, * one-shot promise-based variant intended for synchronous DOM/state checks. * * @example * ```ts * const el = await pollUntil(() => document.getElementById('lazy')); * ``` */ export declare function pollUntil(predicate: () => T | false | null | undefined | Promise, options?: PollUntilOptions): Promise; /** * Resolves on the next animation frame. Falls back to `setTimeout(0)` when * `requestAnimationFrame` is unavailable. Resolves with the frame timestamp * (or `Date.now()` in the fallback case). */ export declare function nextFrame(): Promise; /** * Resolves on the next microtask (or `Promise.resolve().then(...)` fallback * when `queueMicrotask` is unavailable). */ export declare function nextTick(): Promise; //# sourceMappingURL=misc.d.ts.map