export type Fn = (...args: any[]) => any; export type FnAsync = (...args: any[]) => Promise; /** * Executes a function and returns its result or a fallback value if the function throws an error. * * @template T - The type of the function. * @template F - The type of the fallback value. * @param {T} fn - The function to execute. * @param {F} fallback - The fallback value to return if the function throws an error. * @param {...Parameters} args - The parameters to pass to the function. * @returns {ReturnType | F} The function's result or the fallback value if an error is thrown. * * @example * ```typescript * function divide(a: number, b: number): number { * return a / b; * } * * const result = tryFn(divide, 0, 10, 2); * * console.log(result); // 5 or 0 if an error occurs * ``` */ export declare function tryFn(fn: T, fallback: F, ...args: Parameters): ReturnType | F; /** * Executes a function and returns a tuple containing either the result or the error. * * @template T - The type of the function. * @param fn - The function to execute. * @param args - The parameters to pass to the function. * @returns A tuple: * - [result, null] if the function executes successfully. * - [null, error] if an error is thrown during function execution. * * @example * ```typescript * function divide(a: number, b: number): number { * return a / b; * } * * const [result, error] = tryFnWithError(divide, 10, 2); * * if (error) { * console.error('Error occurred:', error); * } else { * console.log('Result:', result); * } * ``` */ export declare function tryFnWithError(fn: T, ...args: Parameters): [ReturnType, null] | [null, unknown]; /** * Executes an asynchronous function and returns its result or a fallback value if the function throws an error. * * @template T - The type of the asynchronous function. * @template F - The type of the fallback value. * @param {T} fn - The asynchronous function to execute. * @param {F} fallback - The fallback value to return if the function throws an error. * @param {...Parameters} args - The parameters to pass to the function. * @returns {Promise | F>} A Promise that resolves with the function's result or the fallback value if an error is thrown. * * @example * ```typescript * async function fetchData(id: number): Promise { * // simulate an API call * return `Data for ID: ${id}`; * } * * const result = await tryFnAsync(fetchData, 'Fallback data', 10); * * console.log(result); // 'Data for ID: 10' or 'Fallback data' if an error occurs * ``` */ export declare function tryFnAsync(fn: T, fallback: F, ...args: Parameters): Promise | F>; /** * Executes an asynchronous function and returns a tuple containing either the result or the error. * * @template T - The type of the asynchronous function. * @param fn - The asynchronous function to execute. * @param args - The parameters to pass to the function. * @returns A Promise that resolves with a tuple: * - [result, null] if the function executes successfully. * - [null, error] if an error is thrown during function execution. * * @example * ```typescript * async function fetchData(id: number): Promise { * // simulate an API call * return `Data for ID: ${id}`; * } * * const [data, error] = await tryFnAsyncWithError(fetchData, 10); * * if (error) { * console.error('Error occurred:', error); * } else { * console.log('Data received:', data); * } * ``` */ export declare function tryFnAsyncWithError(fn: T, ...args: Parameters): Promise<[ReturnType, null] | [null, unknown]>; /** * Pauses execution for a specified amount of time. * * @param {number} time - The amount of time to sleep, in milliseconds. * @returns {Promise} A Promise that resolves after the specified time has passed. * * @example * ```typescript * await sleep(1000); // Pauses execution for 1 second * console.log('1 second has passed'); * ``` */ export declare function sleep(time: number): Promise;