UNPKG

@rustable/utils

Version:

Essential utilities for object cloning, string manipulation, and value comparison in TypeScript, inspired by Rust's standard library.

63 lines (62 loc) 1.69 kB
/** * Represents information about a caller in the stack trace */ interface Caller { /** Function name or file name if anonymous */ name: string; /** Full file path with line and column */ path: string; /** File name without path */ file: string; /** Line number */ line: number; /** Column number */ column: number; } /** * Utility class for getting stack trace and caller information */ export declare class Location { private _stack; constructor(); /** * Parse a single line from the stack trace */ private parseStackLine; /** * Gets the caller at a specific depth in the stack * @param depth Stack depth (0 = current function, 1 = immediate caller, etc.) * @returns Caller information or undefined if depth exceeds stack size * * @example * ```typescript * const loc = new Location(); * const immediate = loc.caller(1); // immediate caller * const deeper = loc.caller(2); // caller's caller * ``` */ caller(depth?: number): Caller | undefined; /** * Gets the current location in the code * @returns Current caller information * * @example * ```typescript * const loc = new Location(); * const current = loc.current(); // {name: 'currentFunction', ...} * ``` */ current(): Caller; /** * Gets all callers in the stack trace * @returns Array of all callers * * @example * ```typescript * const loc = new Location(); * const fullStack = loc.getStack(); // [{name: 'current'}, {name: 'caller'}, ...] * ``` */ stack(): Caller[]; } export {};