Skip to content

Commit

Permalink
fix(csv): do not print empty header line when no columns are given in…
Browse files Browse the repository at this point in the history
… `stringify()` (#4610)
  • Loading branch information
kt3k authored Apr 22, 2024
1 parent 78779a9 commit c93b8a6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion csv/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export function stringify(
output += BYTE_ORDER_MARK;
}

if (headers) {
if (headers && normalizedColumns.length > 0) {
output += normalizedColumns
.map((column) => getEscapedString(column.header, sep))
.join(sep);
Expand Down
4 changes: 2 additions & 2 deletions csv/stringify_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Deno.test({
fn() {
const columns: string[] = [];
const data: string[][] = [];
const output = CRLF;
const output = "";
assertEquals(stringify(data, { columns }), output);
},
},
Expand Down Expand Up @@ -505,7 +505,7 @@ Deno.test({
name: "Valid data, no columns",
fn() {
const data = [[1, 2, 3], [4, 5, 6]];
const output = `${CRLF}1,2,3${CRLF}4,5,6${CRLF}`;
const output = `1,2,3${CRLF}4,5,6${CRLF}`;

assertEquals(stringify(data), output);
},
Expand Down

0 comments on commit c93b8a6

Please sign in to comment.