Skip to content

Commit

Permalink
test(csv-ts-demo-node16): demo assiated with PR adaltas#341
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Jul 10, 2022
1 parent 8bc2d61 commit 44a3005
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
32 changes: 32 additions & 0 deletions demo/ts-module-node16/lib/stringify.ts
@@ -0,0 +1,32 @@

import assert from 'assert'
import { stringify, Stringifier } from 'csv-stringify';

let output: string = '';
// Create the parser
const stringifier: Stringifier = stringify({
delimiter: ':',
encoding: 'utf8'
});
// Use the readable stream api to consume records
stringifier.on('readable', function(){
let record; while ((record = stringifier.read()) !== null) {
output += record
}
});
// Catch any error
stringifier.on('error', function(err){
console.error(err.message)
});
// Test that the parsed records matched what's expected
stringifier.on('end', function(){
assert.deepStrictEqual(
output,
'a:b:c\n1:2:3\n'
)
});
// Write data to the stream
stringifier.write(["a", "b", "c"]);
stringifier.write([1, 2, 3]);
// Close the readable stream
stringifier.end();
30 changes: 30 additions & 0 deletions demo/ts-module-node16/package.json
@@ -0,0 +1,30 @@
{
"name": "csv-ts-demo-node16",
"version": "0.0.0",
"main": "index.js",
"license": "MIT",
"type": "module",
"private": true,
"devDependencies": {
"@types/node": "^18.0.3",
"coffeescript": "^2.7.0",
"mocha": "^10.0.0",
"should": "^13.2.3",
"ts-node": "^10.8.2",
"typescript": "^4.7.4"
},
"mocha": {
"inline-diffs": true,
"recursive": true,
"reporter": "spec",
"require": [
"should",
"coffeescript/register"
],
"throw-deprecation": true,
"timeout": 40000
},
"scripts": {
"test": "mocha 'test/**/*.coffee'"
}
}
7 changes: 7 additions & 0 deletions demo/ts-module-node16/tsconfig.json
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"esModuleInterop": true,
"module": "Node16",
"strict": true,
}
}

0 comments on commit 44a3005

Please sign in to comment.