ndjson-web
v1.1.0
Published
NDJSON parser + serializer using web streams
Downloads
13
Maintainers
Readme
ndjson-web
NDJSON parser + serializer using web streams. Zero dependencies.
Install
npm i ndjson-web
Usage
Parse
import { Parse } from 'ndjson-web'
readable
.pipeThrough(new Parse())
.pipeTo(new WritableStream({
write (obj) {
console.log(obj)
}
}))
Serialize
import { Stringify } from 'ndjson-web'
const items = [{ one: 1 }, { two: 2 }, { three: 3 }]
new ReadableStream({
pull (controller) {
const item = items.shift()
return item ? controller.enqueue(item) : controller.close()
}
}).pipeThrough(new Stringify()).pipeTo(writable)
Contributing
Feel free to join in. All welcome. Please open an issue!
License
Dual-licensed under MIT + Apache 2.0