1.1.0 • Published 11 months ago

ndjson-web v1.1.0

Weekly downloads
-
License
Apache-2.0 OR MIT
Repository
github
Last release
11 months ago

ndjson-web

Build JavaScript Style Guide

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