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

Function formatNodeValues

packages/utils/src/lib/text-formats/ascii/tree.ts:65–104  ·  view source on GitHub ↗
(
  values: TreeNode['values'],
  keysMaxWidths: Record<string, number>,
)

Source from the content-addressed store, hash-verified

63}
64
65function formatNodeValues(
66 values: TreeNode['values'],
67 keysMaxWidths: Record<string, number>,
68): string {
69 if (!values) {
70 return '';
71 }
72
73 if ('coverage' in values && typeof values.coverage === 'number') {
74 const percentage = coveragePercentage(values.coverage);
75 const maxLength = coveragePercentage(1).length;
76 const formattedCoverage = `${percentage.padStart(maxLength, ' ')} %`;
77 if (!Array.isArray(values.missing) || values.missing.length === 0) {
78 return formattedCoverage;
79 }
80 const formattedMissing = values.missing
81 .map(({ name, startLine, endLine }): string => {
82 const range =
83 startLine === endLine
84 ? startLine.toString()
85 : `${startLine}-${endLine}`;
86 return name ? `${name} (${range})` : range;
87 })
88 .join(', ');
89 return `${formattedCoverage}${' '.repeat(COL_GAP)}${formattedMissing}`;
90 }
91
92 const valuesMap = new Map(
93 Object.entries(values).filter(
94 (pair): pair is [string, string | number] =>
95 typeof pair[1] === 'string' || typeof pair[1] === 'number',
96 ),
97 );
98 return Object.entries(keysMaxWidths)
99 .map(([key, maxWidth]) => {
100 const value = valuesMap.get(key)?.toString() ?? '';
101 return value.padStart(maxWidth, ' ');
102 })
103 .join(' '.repeat(COL_GAP));
104}
105
106function flatten(
107 node: TreeNode,

Callers 1

formatTreeNodeFunction · 0.85

Calls 2

coveragePercentageFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected