Skip to content

Commit

Permalink
fix(csv/csv_stringify_stream): output headers based on columns opti…
Browse files Browse the repository at this point in the history
…on (#3293)
  • Loading branch information
uki00a authored Mar 30, 2023
1 parent f980ab9 commit 87f4a8b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions csv/csv_stringify_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ export class CsvStringifyStream<TOptions extends CsvStringifyStreamOptions>

super(
{
start(controller) {
if (columns && columns.length > 0) {
try {
controller.enqueue(
stringify([columns], { separator, headers: false }),
);
} catch (error) {
controller.error(error);
}
}
},
transform(chunk, controller) {
try {
controller.enqueue(
Expand Down
1 change: 1 addition & 0 deletions csv/csv_stringify_stream_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Deno.test({
output.push(r);
}
assertEquals(output, [
"id,name\r\n",
"1,foo\r\n",
"2,bar\r\n",
"3,baz\r\n",
Expand Down

0 comments on commit 87f4a8b

Please sign in to comment.