ndjson-fe

1.2.10 • Public • Published

ndjson-fe

Node.js Test Runner GitHub code size in bytes GitHub package.json version GitHub

This library takes a ndjson (Newline Delimited JSON) stream and outputs events containing each item when it receives a full JSON object.

Why?

For example, if you have the following data coming from a stream:

{"a": 1}
{"b": 2}
{"c": 3}

The above data will emit three events when you listen to "next":

feed.on('next', console.log)
 // {a: 1}
 // {b: 2}
 // {c: 3}

Piping

const fs = require('fs');
const ndJsonFe = require('ndjson-fe');
const feed = ndJsonFe();

feed.on('next', row => {
  console.log('The next row is: ', row);
});

feed.on('error', e => {
  console.log('There was an error: ', e);
});

feed.on('end', () => {
  console.log('The stream has finished');
});

const reader = fs.createReadStream('./test.json');
reader.pipe(feed)

Manual

const ndJsonFe = require('ndjson-fe');
const feed = ndJsonFe();

feed.on('next', row => {
  console.log('The next row is: ', row);
});

feed.on('error', e => {
  console.log('There was an error: ', e);
});

feed.on('end', () => {
  console.log('The stream has finished');
});

feed.write(`{ "ONE": 1, "TWO": 2 }\n`);
feed.write(`{ "THREE": 1, `);
feed.write(`"FOUR": 4 }\n`);
feed.write(`{ "FIVE": 5, "SIX": 6 }\n{ "SEVEN": 7`);
feed.write(`, "EIGHT": 8 }`);
feed.write(`{ "BROKEN\n`);
feed.write(`{ "NINE": 9 }\n`);
feed.end();

Dependencies (0)

    Dev Dependencies (1)

    Package Sidebar

    Install

    npm i ndjson-fe

    Weekly Downloads

    14

    Version

    1.2.10

    License

    MIT

    Unpacked Size

    4.47 kB

    Total Files

    4

    Last publish

    Collaborators

    • markwylde