UNPKG

@socketsecurity/lib

Version:

Core utilities and infrastructure for Socket.dev security tools

28 lines (27 loc) 1 kB
/** * @fileoverview Common function utilities for control flow and caching. * Provides noop, once, and other foundational function helpers. */ // Type definitions export type AsyncFunction<TArgs extends unknown[], TResult> = (...args: TArgs) => Promise<TResult>; export type AnyFunction = (...args: unknown[]) => unknown; /** * A no-op function that does nothing. */ /*@__NO_SIDE_EFFECTS__*/ export declare function noop(): void; /** * Create a function that only executes once. */ /*@__NO_SIDE_EFFECTS__*/ export declare function once<T extends AnyFunction>(fn: T): T; /** * Wrap an async function to silently catch and ignore errors. */ /*@__NO_SIDE_EFFECTS__*/ export declare function silentWrapAsync<TArgs extends unknown[], TResult>(fn: AsyncFunction<TArgs, TResult>): (...args: TArgs) => Promise<TResult | undefined>; /** * Execute a function with tail call optimization via trampoline. */ /*@__NO_SIDE_EFFECTS__*/ export declare function trampoline<T extends AnyFunction>(fn: T): T;