(rows: Record<string, unknown>[])
| 45 | } |
| 46 | |
| 47 | export function formatTable(rows: Record<string, unknown>[]): string { |
| 48 | if (rows.length === 0) return '(empty)'; |
| 49 | |
| 50 | const keys = Object.keys(rows[0]!); |
| 51 | const widths = keys.map(k => |
| 52 | Math.max(k.length, ...rows.map(r => String(r[k] ?? '').length)), |
| 53 | ); |
| 54 | |
| 55 | const header = keys.map((k, i) => k.toUpperCase().padEnd(widths[i]!)).join(' '); |
| 56 | const separator = widths.map(w => '-'.repeat(w)).join(' '); |
| 57 | const body = rows.map(r => |
| 58 | keys.map((k, i) => String(r[k] ?? '').padEnd(widths[i]!)).join(' '), |
| 59 | ); |
| 60 | |
| 61 | return [header, separator, ...body].join('\n'); |
| 62 | } |
no outgoing calls
no test coverage detected