wrap-json-stream

0.1.0 • Public • Published

wrap-json-stream

Wrap a duplex stream with JSONStream parse and stringify.

npm status Dependency status

example

const json = require('wrap-json-stream')
    , through2 = require('through2')
 
const wrapped = json(through2.obj(function(obj, _, next){
  obj.y = obj.x*2
  next(null, obj)
}))
 
wrapped.on('data', (data) => console.log(data.toString()))
wrapped.write('{"x":1}\n{"x":2}')
{"x":1,"y":2}

{"x":2,"y":4}

json(stream(s), [opts])

Options:

  • fwd: array of events to forward from the inner stream to the outer
  • inherit: array of properties to inherit
const inner = someStream()
inner.name = 'my-stream'
 
const outer = json(inner, { inherit: ['name'], fwd: ['sync'] })
 
outer.on('sync', () => console.log(outer.name))
inner.emit('sync')

install

With npm do:

npm install wrap-json-stream

license

MIT © Vincent Weevers

Package Sidebar

Install

npm i wrap-json-stream

Weekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • vweevers