This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Useful when passing an error from try/catch to a logger | |
| export function stringifyUnknown(obj: unknown): string { | |
| const defaultErrorString = 'unknown error' | |
| const notNullish = obj ?? defaultErrorString | |
| if (typeof notNullish === 'string') { | |
| return notNullish | |
| } | |
| if (typeof notNullish === 'object') { | |
| return JSON.stringify(notNullish, ['message', 'arguments', 'type', 'name', 'stack'], 2) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface ColorItem { | |
| value: string | number | object | |
| color?: string | |
| } | |
| type Input = (string | ColorItem)[] | |
| /** | |
| * Logs data to the console with customizable colors and formatting. | |
| * @param {Input} data - An array of data to log. Each item can be a string, number, or object with a "value" property. |
OlderNewer