Created
February 19, 2020 01:32
-
-
Save friendlyanon/42ffc5ed73adc755d90559045bbb2102 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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