Skip to content

Instantly share code, notes, and snippets.

@friendlyanon
Created February 19, 2020 01:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save friendlyanon/42ffc5ed73adc755d90559045bbb2102 to your computer and use it in GitHub Desktop.
Save friendlyanon/42ffc5ed73adc755d90559045bbb2102 to your computer and use it in GitHub Desktop.
function* parseNdjson(ndjson) {
let i = 0;
do {
const newline = ndjson.indexOf("\n", i);
const string = newline === -1 ? ndjson.slice(i) : ndjson.slice(i, newline);
const json = string.trim();
if (json) {
yield JSON.parse(json);
}
i = newline + 1;
} while (i > 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment