UNPKG

topkat-utils

Version:

A comprehensive collection of TypeScript/JavaScript utility functions for common programming tasks. Includes validation, object manipulation, date handling, string formatting, and more. Zero dependencies, fully typed, and optimized for performance.

32 lines (29 loc) 1.58 kB
export declare function timeout(ms: any, fn?: () => void): Promise<void>; export declare function runAsync(callback: any, milliseconds$?: number): Promise<void>; /** * * @param {Function} callback function that shall return ===true asynchronously * @param {Number} timeoutSec default:10; general timeout in seconds * @param {Boolean|String} errorAfterNSeconds default:true output an error in case of timeout, can be the displayed error message * @param {*} cliOutput write a cli progress to show that a process is running */ export declare function waitUntilTrue(callback: any, timeoutSec?: number, errorAfterNSeconds?: boolean, cliOutput?: boolean): Promise<void>; /** Allow to perform an action in a delayed loop, useful for example to avoid reaching limits on servers. This function can be securely called multiple times. * @param {Function} callback * @param {Number} time default: 500ms; * @param {Function} errorCallback default: e => C.error(e) */ export declare function executeInDelayedLoop(callback: any, time?: number, errorCallback?: (e: any) => any): Promise<void>; /** Will first wait before calling callback every seconds configured in retrySeconds array */ export declare function retryWithDelay(callback: Function, retrySeconds: number[]): Promise<void>; /** Use this timer to measure code performances. * @example ```typescript const time = perfTimer() for(let i = 0; i < 9999;i++) longProcess() console.log('Process took ' + time.end()) ``` */ export declare function perfTimer(unit?: 'ms' | 'seconds'): { start: number; end(): string; };