(tree: Tree)
| 10 | const COL_GAP = 2; |
| 11 | |
| 12 | export function formatAsciiTree(tree: Tree): string { |
| 13 | const nodes = flatten(tree.root); |
| 14 | const maxWidth = Math.max( |
| 15 | ...nodes.map(({ node, level }) => level * INDENT_CHARS + node.name.length), |
| 16 | ); |
| 17 | const keysMaxWidths = |
| 18 | tree.type === 'coverage' |
| 19 | ? {} |
| 20 | : nodes.reduce<Record<string, number>>( |
| 21 | (acc, { node }) => ({ |
| 22 | ...acc, |
| 23 | ...Object.fromEntries( |
| 24 | Object.entries(node.values ?? {}).map(([key, value]) => [ |
| 25 | key, |
| 26 | Math.max(acc[key] ?? 0, `${value}`.length), |
| 27 | ]), |
| 28 | ), |
| 29 | }), |
| 30 | {}, |
| 31 | ); |
| 32 | |
| 33 | return formatTreeNode(tree.root, '', maxWidth, keysMaxWidths) |
| 34 | .map(line => `${line}\n`) |
| 35 | .join(''); |
| 36 | } |
| 37 | |
| 38 | function formatTreeNode( |
| 39 | node: TreeNode, |
no test coverage detected