(input: unknown)
| 80 | * Safely extracts text content from various input formats |
| 81 | */ |
| 82 | export function extractTextContent(input: unknown): string { |
| 83 | if (typeof input === 'string') { |
| 84 | return input.trim() |
| 85 | } |
| 86 | |
| 87 | if (input && typeof input === 'object') { |
| 88 | try { |
| 89 | return JSON.stringify(input) |
| 90 | } catch (error) { |
| 91 | logger.warn('Failed to stringify input object', { |
| 92 | inputType: typeof input, |
| 93 | error: toError(error).message, |
| 94 | }) |
| 95 | return '' |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | return String(input || '') |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Creates a preview of text for logging (truncated) |
no test coverage detected