From 44a3005ee50ca70ecd09decad8250ab49b3ee7de Mon Sep 17 00:00:00 2001 From: David Worms Date: Sun, 10 Jul 2022 22:31:57 +0200 Subject: [PATCH] test(csv-ts-demo-node16): demo assiated with PR #341 --- demo/ts-module-node16/lib/stringify.ts | 32 ++++++++++++++++++++++++++ demo/ts-module-node16/package.json | 30 ++++++++++++++++++++++++ demo/ts-module-node16/tsconfig.json | 7 ++++++ 3 files changed, 69 insertions(+) create mode 100644 demo/ts-module-node16/lib/stringify.ts create mode 100644 demo/ts-module-node16/package.json create mode 100644 demo/ts-module-node16/tsconfig.json diff --git a/demo/ts-module-node16/lib/stringify.ts b/demo/ts-module-node16/lib/stringify.ts new file mode 100644 index 000000000..f4cf1db94 --- /dev/null +++ b/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(); diff --git a/demo/ts-module-node16/package.json b/demo/ts-module-node16/package.json new file mode 100644 index 000000000..3b9d3198e --- /dev/null +++ b/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'" + } +} diff --git a/demo/ts-module-node16/tsconfig.json b/demo/ts-module-node16/tsconfig.json new file mode 100644 index 000000000..b7a38adc0 --- /dev/null +++ b/demo/ts-module-node16/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "esModuleInterop": true, + "module": "Node16", + "strict": true, + } +}