( node: TreeNode, prefix: string, maxWidth: number, keysMaxWidths: Record<string, number>, )
| 36 | } |
| 37 | |
| 38 | function formatTreeNode( |
| 39 | node: TreeNode, |
| 40 | prefix: string, |
| 41 | maxWidth: number, |
| 42 | keysMaxWidths: Record<string, number>, |
| 43 | ): string[] { |
| 44 | const childPrefix = prefix.replace(/[└─]/g, ' ').replace(/├/g, '│'); |
| 45 | |
| 46 | const prefixedName = `${prefix}${node.name}`; |
| 47 | const padding = ' '.repeat(maxWidth + COL_GAP * 2 - prefixedName.length); |
| 48 | const values = formatNodeValues(node.values, keysMaxWidths); |
| 49 | const offsetValues = values ? `${padding}${values}` : ''; |
| 50 | const formattedNode = `${prefixedName}${offsetValues}`; |
| 51 | |
| 52 | return [ |
| 53 | formattedNode, |
| 54 | ...(node.children?.flatMap((child, i, arr) => |
| 55 | formatTreeNode( |
| 56 | child, |
| 57 | i === arr.length - 1 ? `${childPrefix}└── ` : `${childPrefix}├── `, |
| 58 | maxWidth, |
| 59 | keysMaxWidths, |
| 60 | ), |
| 61 | ) ?? []), |
| 62 | ]; |
| 63 | } |
| 64 | |
| 65 | function formatNodeValues( |
| 66 | values: TreeNode['values'], |
no test coverage detected