MCPcopy Index your code
hub / github.com/code-pushup/cli / columnsToStringArray

Function columnsToStringArray

packages/utils/src/lib/text-formats/table.ts:41–70  ·  view source on GitHub ↗
({
  rows,
  columns = [],
}: Pick<Table, 'columns' | 'rows'>)

Source from the content-addressed store, hash-verified

39
40// Determine effective columns based on the input rows and optional columns parameter
41export function columnsToStringArray({
42 rows,
43 columns = [],
44}: Pick<Table, 'columns' | 'rows'>): string[] {
45 const firstRow = rows.at(0);
46 const primitiveRows = Array.isArray(firstRow);
47
48 if (typeof columns.at(0) === 'string' && !primitiveRows) {
49 throw new Error('invalid union type. Caught by model parsing.');
50 }
51
52 if (columns.length === 0) {
53 if (Array.isArray(firstRow)) {
54 return firstRow.map((_, idx) => String(idx));
55 }
56 return Object.keys(firstRow as object);
57 }
58
59 // columns = ['right', 'left']; row = ['100 ms', '200 ms'] => 1,2,3
60 if (typeof columns.at(0) === 'string') {
61 return columns.map(String);
62 }
63
64 // columns = [
65 // {key: 'prop1' label: 'Property 1'},
66 // {key: 'prop2'}
67 // ]; row = [ {prop1: '100 ms', prop2: '200 ms'}] => Property 1, Prop2
68 const cols = columns as TableColumnObject[];
69 return cols.map(({ label, key }) => label ?? capitalize(key));
70}
71
72export function getColumnAlignmentForKeyAndIndex(
73 targetKey: string,

Callers 3

table.unit.test.tsFile · 0.85
tableFunction · 0.85
tableSectionFunction · 0.85

Calls 1

capitalizeFunction · 0.85

Tested by

no test coverage detected