/** * create a singleton using the function provided. * @param func - a function that will be called to create the instance. * @returns A function that return a singleton instance of the type T for a given label. */ declare function createSingleton(func: (...args: any[]) => T): (label?: string, ...args: any[]) => T; /** * given a function fn, repeat it every interval milliseconds. * rc.start() to start the repeater * rc.stop() to stop the repeater * createRepeater(fn, 5000); // run fn every 5 seconds * @param fn * @param interval * @returns */ declare function createRepeater(fn: Function, interval: number): { start(): void; stop(): void; }; type StepFn = (value: I, ...args: A) => O | Promise; declare class Chainer extends Promise { private chainPromise; constructor(initial: T); step(fn: StepFn, ...args: any[]): Chainer; s(fn: StepFn, ...args: any[]): Chainer; static from(initial: T): Chainer; } /** * chains multiple functions/steps together. Each step can be synchronous or asynchronous. * Each step receives the result of the previous step as the first parameter. more parameters can be passed after that. * To calculate the final result, use `await` on the returned Chainer. * @param initial initial value to start * @returns final result * @example * ```ts * import { chainer } from "@devbro/pashmak/helpers"; * const add = (x: number, y: number, z: number) => x + y + z; * const multiply = (x: number, y: number) => x * y; * * const result = await chainer(4) * .step(add, 2, 0) // 4 + 2 = 6 * .step(multiply, 3) // 6 * 3 = 18 */ declare function chainer(initial: T): Chainer; /** * Checks if a variable is a class constructor. * @param variable - The variable to check * @returns True if the variable is a class, false otherwise */ declare function isClass(variable: any): boolean; /** * Checks if a variable is a function (but not a class constructor). * @param variable - The variable to check * @returns True if the variable is a function and not a class, false otherwise */ declare function isFunction(variable: any): boolean; export { chainer, createRepeater, createSingleton, isClass, isFunction };