Skip to content

Commit

Permalink
fix: csv export (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
alarv authored Oct 23, 2024
1 parent 52d0afb commit d9e14da
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/app/api/datasets/export/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ function generateCSVFromData(
return row[header.key];
});
});
const resultRows = rowsIn2DArray
.map((row) => row.join(','))
.map((row) => {
if (row.toString().includes(',')) {
return `"${row}"`;
const resultRows = rowsIn2DArray.map((rowValues) => {
const escapedRowValues = rowValues.map((value) => {
if (value.toString().includes(',')) {
return `"${value}"`;
}
return row;
return value;
});

return escapedRowValues.join(',');
});

return [headerRow, ...resultRows].join('\n');
}

Expand Down

0 comments on commit d9e14da

Please sign in to comment.