File tree 3 files changed +53
-0
lines changed
demo/ts-moduleresolution-node16-cjs
3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ import assert from 'assert'
3
+ import { stringify , Stringifier } from 'csv-stringify' ;
4
+
5
+ let output : string = '' ;
6
+ // Create the parser
7
+ const stringifier : Stringifier = stringify ( {
8
+ delimiter : ':' ,
9
+ encoding : 'utf8'
10
+ } ) ;
11
+ // Use the readable stream api to consume records
12
+ stringifier . on ( 'readable' , function ( ) {
13
+ let record ; while ( ( record = stringifier . read ( ) ) !== null ) {
14
+ output += record
15
+ }
16
+ } ) ;
17
+ // Catch any error
18
+ stringifier . on ( 'error' , function ( err ) {
19
+ console . error ( err . message )
20
+ } ) ;
21
+ // Test that the parsed records matched what's expected
22
+ stringifier . on ( 'end' , function ( ) {
23
+ assert . deepStrictEqual (
24
+ output ,
25
+ 'a:b:c\n1:2:3\n'
26
+ )
27
+ } ) ;
28
+ // Write data to the stream
29
+ stringifier . write ( [ "a" , "b" , "c" ] ) ;
30
+ stringifier . write ( [ 1 , 2 , 3 ] ) ;
31
+ // Close the readable stream
32
+ stringifier . end ( ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " csv-demo-ts-moduleresolution-node16-cjs" ,
3
+ "version" : " 0.2.1" ,
4
+ "main" : " index.js" ,
5
+ "license" : " MIT" ,
6
+ "private" : true ,
7
+ "devDependencies" : {
8
+ "typescript" : " ^4.9.5"
9
+ },
10
+ "scripts" : {
11
+ "typecheck" : " tsc --noEmit"
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ {
2
+ "compilerOptions" : {
3
+ "esModuleInterop" : true ,
4
+ "module" : " CommonJS" ,
5
+ "moduleResolution" : " node16" ,
6
+ "strict" : true
7
+ }
8
+ }
You can’t perform that action at this time.
0 commit comments