-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(csv-issues-esm): reproduce issue #391
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"esModuleInterop": true, | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"strict": true, | ||
} | ||
} |