(vars: object[])
| 308 | * @returns A CSV string. |
| 309 | */ |
| 310 | export 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 | } |
no test coverage detected
searching dependent graphs…