Skip to content

Commit

Permalink
test(csv-issues-esm): reproduce issue #391
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Aug 25, 2023
1 parent caca5c3 commit 256d398
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 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')
})
8 changes: 8 additions & 0 deletions demo/issues-esm/tsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"esModuleInterop": true,
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
}
}

0 comments on commit 256d398

Please sign in to comment.