| 19 | } |
| 20 | |
| 21 | export function formatKeyValue(obj: Record<string, unknown>, indent = 0): string { |
| 22 | const prefix = ' '.repeat(indent); |
| 23 | const lines: string[] = []; |
| 24 | |
| 25 | for (const [key, value] of Object.entries(obj)) { |
| 26 | if (value === null || value === undefined) continue; |
| 27 | if (Array.isArray(value)) { |
| 28 | lines.push(`${prefix}${key}:`); |
| 29 | for (const item of value) { |
| 30 | if (typeof item === 'object' && item !== null) { |
| 31 | lines.push(`${prefix} - ${formatKeyValue(item as Record<string, unknown>, indent + 4).trimStart()}`); |
| 32 | } else { |
| 33 | lines.push(`${prefix} - ${String(item)}`); |
| 34 | } |
| 35 | } |
| 36 | } else if (typeof value === 'object') { |
| 37 | lines.push(`${prefix}${key}:`); |
| 38 | lines.push(formatKeyValue(value as Record<string, unknown>, indent + 2)); |
| 39 | } else { |
| 40 | lines.push(`${prefix}${key}: ${String(value)}`); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | return lines.join('\n'); |
| 45 | } |
| 46 | |
| 47 | export function formatTable(rows: Record<string, unknown>[]): string { |
| 48 | if (rows.length === 0) return '(empty)'; |