From 2fc56dab7dacabde1c8c03374240f43c165b69bf Mon Sep 17 00:00:00 2001 From: Thai Pangsakulyanont Date: Wed, 1 Sep 2021 03:37:12 +0700 Subject: [PATCH 1/2] Add example usage with modern ECMAScript modules Using top-level await, and for-await-of constructs to make code look more sequential and straightforward. --- readme.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/readme.md b/readme.md index 1209977..1d89c92 100644 --- a/readme.md +++ b/readme.md @@ -31,6 +31,16 @@ fs.createReadStream('data.txt') }) ``` +With modern [ECMAScript modules](https://nodejs.org/api/esm.html): + +```js +import ndjson from 'ndjson' +import fs from 'fs' + +for await (const line of fs.createReadStream('data.txt').pipe(ndjson.parse())) { + console.log(line) +} +``` ##### Options From f007f797590c28de36a5352a06d32b74880402c0 Mon Sep 17 00:00:00 2001 From: Thai Pangsakulyanont Date: Wed, 1 Sep 2021 03:38:04 +0700 Subject: [PATCH 2/2] Make the modern example functionally equivalent of the example above --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 1d89c92..49981ee 100644 --- a/readme.md +++ b/readme.md @@ -37,8 +37,8 @@ With modern [ECMAScript modules](https://nodejs.org/api/esm.html): import ndjson from 'ndjson' import fs from 'fs' -for await (const line of fs.createReadStream('data.txt').pipe(ndjson.parse())) { - console.log(line) +for await (const obj of fs.createReadStream('data.txt').pipe(ndjson.parse())) { + // obj is a javascript object } ```