From 256d398ae66b9eb10fd6886e7d6ef4c0d5fa9a96 Mon Sep 17 00:00:00 2001 From: David Worms Date: Fri, 25 Aug 2023 14:26:04 +0200 Subject: [PATCH] test(csv-issues-esm): reproduce issue #391 --- demo/issues-esm/lib/391.ts | 30 ++++++++++++++++++++++++++++++ demo/issues-esm/tsconfig.json | 8 ++++++++ 2 files changed, 38 insertions(+) create mode 100644 demo/issues-esm/lib/391.ts create mode 100644 demo/issues-esm/tsconfig.json diff --git a/demo/issues-esm/lib/391.ts b/demo/issues-esm/lib/391.ts new file mode 100644 index 00000000..38a5aedc --- /dev/null +++ b/demo/issues-esm/lib/391.ts @@ -0,0 +1,30 @@ + +import assert from 'assert' +import { stringify, Stringifier } from 'csv-stringify'; + +// Create the parser +const output: string[] = []; +const stringifier: Stringifier = stringify({ + header: true, + cast: { + boolean: (value, ctx) => { + if (ctx.header) return String(value) + if (ctx.column === 'Removed' && value === false) { + return '0' + } + return String(value) + } + } +}); +// Write data to the stream +stringifier.write({a: 1, b: 2, c: 3}); +// Close the readable stream +stringifier.end(); +// Read output +stringifier.on('data', (buf) => { + output.push(buf.toString()); +}) +stringifier.on('end', () => { + console.log(output); + assert(output.join(), 'a,b,c\n1,2,3\n') +}) diff --git a/demo/issues-esm/tsconfig.json b/demo/issues-esm/tsconfig.json new file mode 100644 index 00000000..53445dd7 --- /dev/null +++ b/demo/issues-esm/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "esModuleInterop": true, + "module": "NodeNext", + "moduleResolution": "NodeNext", + "strict": true, + } +}