(rows: string[][], options = { json: false } as FormatTableOptions)
| 7 | } |
| 8 | |
| 9 | export function formatTable(rows: string[][], options = { json: false } as FormatTableOptions): string { |
| 10 | if (options.json) { |
| 11 | const result = rows.reduce((acc, [name, value]) => { |
| 12 | acc[slugify(name)] = value |
| 13 | return acc |
| 14 | }, {}) |
| 15 | return JSON.stringify(result, null, 2) |
| 16 | } |
| 17 | |
| 18 | const maxPad = rows.reduce((acc, curr) => Math.max(acc, curr[0].length), 0) |
| 19 | return rows.map(([left, right]) => `${left.padEnd(maxPad)} : ${right}`).join('\n') |
| 20 | } |
no test coverage detected