(value: unknown)
| 82 | }; |
| 83 | |
| 84 | export const formatLogValue = (value: unknown): string => { |
| 85 | if (value === null) { |
| 86 | return 'null'; |
| 87 | } |
| 88 | |
| 89 | if (value === undefined) { |
| 90 | return 'undefined'; |
| 91 | } |
| 92 | |
| 93 | if (typeof value === 'string') { |
| 94 | return truncateIfNeeded(value); |
| 95 | } |
| 96 | |
| 97 | if (typeof value === 'number' || typeof value === 'boolean') { |
| 98 | return String(value); |
| 99 | } |
| 100 | |
| 101 | if (typeof value === 'function') { |
| 102 | const name = value.name || 'anonymous'; |
| 103 | return `[Function: ${name}]`; |
| 104 | } |
| 105 | |
| 106 | if (value instanceof Error) { |
| 107 | const parts = [ |
| 108 | `${value.name}: ${value.message}`, |
| 109 | value.stack ? value.stack.split('\n').slice(1).join('\n') : '', |
| 110 | ].filter(Boolean); |
| 111 | return truncateIfNeeded(parts.join('\n')); |
| 112 | } |
| 113 | |
| 114 | try { |
| 115 | const json = JSON.stringify(value); |
| 116 | return truncateIfNeeded(json); |
| 117 | } catch { |
| 118 | const preview = getObjectPreview(value as object); |
| 119 | return `[Unserializable object: ${preview}]`; |
| 120 | } |
| 121 | }; |
| 122 | |
| 123 | const getObjectPreview = (obj: object): string => { |
| 124 | try { |
no test coverage detected