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, + } +}