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

Function getColumnAlignments

packages/utils/src/lib/text-formats/table.ts:107–138  ·  view source on GitHub ↗
(tableData: Table)

Source from the content-addressed store, hash-verified

105}
106
107export function getColumnAlignments(tableData: Table): TableAlignment[] {
108 const { rows, columns = [] } = tableData;
109
110 // this is caught by the table schema in @code-pushup/models
111 if (rows.at(0) == null) {
112 throw new Error('first row can`t be undefined.');
113 }
114
115 if (Array.isArray(rows.at(0))) {
116 const firstPrimitiveRow = rows.at(0) as TableCellValue[];
117 return Array.from({ length: firstPrimitiveRow.length }).map((_, idx) =>
118 getColumnAlignmentForIndex(idx, columns as TableColumnPrimitive[]),
119 );
120 }
121
122 const biggestRow = rows
123 .toSorted((a, b) => Object.keys(a).length - Object.keys(b).length)
124 .at(-1);
125 if (columns.length > 0) {
126 return columns.map((column, idx) =>
127 typeof column === 'string'
128 ? column
129 : getColumnAlignmentForKeyAndIndex(
130 column.key,
131 idx,
132 columns as TableColumnObject[],
133 ),
134 );
135 }
136
137 return Object.keys(biggestRow ?? {}).map(_ => 'center');
138}

Callers 2

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

Calls 2

Tested by

no test coverage detected