MCPcopy Index your code
hub / github.com/promptfoo/promptfoo / serializeObjectArrayAsCSV

Function serializeObjectArrayAsCSV

src/csv.ts:310–325  ·  view source on GitHub ↗
(vars: object[])

Source from the content-addressed store, hash-verified

308 * @returns A CSV string.
309 */
310export function serializeObjectArrayAsCSV(vars: object[]): string {
311 invariant(vars.length > 0, 'No variables to serialize');
312 const columnNames = Object.keys(vars[0]).join(',');
313 // This generated test-case dataset is intentionally not formula-escaped because
314 // prefixing a cell would corrupt vars on round-trip. Formula escaping is applied
315 // only by the eval result export path.
316 const rows = vars
317 .map(
318 (result) =>
319 `"${Object.values(result)
320 .map((value) => value.toString().replace(/"/g, '""'))
321 .join('","')}"`,
322 )
323 .join('\n');
324 return [columnNames, rows].join('\n') + '\n';
325}

Callers 2

csv.test.tsFile · 0.90
doGenerateDatasetFunction · 0.90

Calls 3

invariantFunction · 0.85
valuesMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…