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

Function rowToStringArray

packages/utils/src/lib/text-formats/table.ts:10–38  ·  view source on GitHub ↗
({ rows, columns = [] }: Table)

Source from the content-addressed store, hash-verified

8import { capitalize } from '../case-conversions.js';
9
10export function rowToStringArray({ rows, columns = [] }: Table): string[][] {
11 if (Array.isArray(rows.at(0)) && typeof columns.at(0) === 'object') {
12 throw new TypeError(
13 'Column can`t be object when rows are primitive values',
14 );
15 }
16
17 return rows.map(row => {
18 // row = ['100 ms', '200 ms']
19 if (Array.isArray(row)) {
20 return row.map(String);
21 }
22
23 // row = { prop1: '100 ms', prop2: '200 ms' }
24 const objectRow = row;
25
26 // columns [] || column.at(0) = 'center'
27 if (columns.length === 0 || typeof columns.at(0) === 'string') {
28 return Object.values(objectRow).map(value =>
29 value == null ? '' : String(value),
30 );
31 }
32
33 // column = {key: 'prop1'}
34 return (columns as TableColumnObject[]).map(({ key }): string =>
35 objectRow[key] == null ? '' : String(objectRow[key]),
36 );
37 });
38}
39
40// Determine effective columns based on the input rows and optional columns parameter
41export function columnsToStringArray({

Callers 3

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

Calls

no outgoing calls

Tested by

no test coverage detected