MCPcopy Create free account
hub / github.com/code-pushup/cli / formatTreeNode

Function formatTreeNode

packages/utils/src/lib/text-formats/ascii/tree.ts:38–63  ·  view source on GitHub ↗
(
  node: TreeNode,
  prefix: string,
  maxWidth: number,
  keysMaxWidths: Record<string, number>,
)

Source from the content-addressed store, hash-verified

36}
37
38function 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
65function formatNodeValues(
66 values: TreeNode['values'],

Callers 1

formatAsciiTreeFunction · 0.85

Calls 1

formatNodeValuesFunction · 0.85

Tested by

no test coverage detected