@naturalcycles/nodejs-lib
Version:
Standard library for Node.js
29 lines (28 loc) • 992 B
TypeScript
/// <reference types="node" />
export interface InspectIfPossibleOptions extends NodeJS.InspectOptions {
/**
* @default 10_000
*/
maxLen?: number;
/**
* @default false
* Set to true to not print Error.stack (keeping just Error.message).
*/
noErrorStack?: boolean;
}
/**
* Transforms ANY to human-readable string (via util.inspect mainly).
* Safe (no error throwing).
*
* Correclty prints Errors, AppErrors, ErrorObjects: error.message + \n + inspect(error.data)
*
* Enforces max length (default to 10_000, pass 0 to skip it).
*
* Logs numbers as-is, e.g: `6`.
* Logs strings as-is (without single quotes around, unlike default util.inspect behavior).
* Otherwise - just uses util.inspect() with reasonable defaults.
*
* Returns 'empty_string' if empty string is passed.
* Returns 'undefined' if undefined is passed (default util.inspect behavior).
*/
export declare function inspectAny(obj: any, opt?: InspectIfPossibleOptions): string;