@fjell/logging
Version:
Logging for Fjell
34 lines (33 loc) • 1.45 kB
TypeScript
/**
* Cross-platform utility functions that work in both Node.js and browser environments
*/
/**
* CRITICAL: Safe JSON stringify that NEVER throws and handles circular references
* This function is designed to prevent application crashes from non-serializable objects
*
* Features:
* - Handles circular references gracefully
* - Never throws errors (returns safe fallback strings instead)
* - Uses custom implementation for consistent behavior
* - Maintains compatibility with existing tests
*/
export declare const stringifyJSON: (obj: any, visited?: Set<any>) => string;
/**
* Simple string formatting that works in both Node.js and browser environments
* Handles format specifiers like %s, %d, %j, %i, %f similar to Node.js util.format
*/
export declare const safeFormat: (message: string, ...args: any[]) => string;
/**
* Safe object inspection that works in both Node.js and browser environments
* Uses stringifyJSON for consistent, safe serialization
*/
export declare const safeInspect: (obj: any) => string;
/**
* CRITICAL: Safe JSON.stringify for entire log entries
* This is specifically for structured logging where the entire log object is stringified
* NEVER throws - will return a safe error message instead of crashing the application
*
* @param obj - The log entry object to stringify
* @returns A JSON string that is guaranteed to be serializable
*/
export declare const safeJSONStringify: (obj: any) => string;