serialize-stream
Stream as json, ndjson, or csv.
Last updated 4 years ago by dguttman .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install serialize-stream 
SYNC missed versions from official npm registry.

serialize-stream

Stream json, ndjson, or csv.

This is useful if you have an API and want to stream different formats depending on a param.

Uses csv-write-stream and JSONStream under the hood.

Example


var ss = require('serialize-stream')

ss('csv')
  .on('data', console.log)
  .end({a: 1, b: 2, c: 3})

// a,b,c
// 1,2,3

ss('json')
  .on('data', console.log)
  .end({a: 1, b: 2, c: 3})

// [
// {"a":1,"b":2,"c":3}
// ]

ss('ndjson')
  .on('data', console.log)
  .end({a: 1, b: 2, c: 3})

// {"a":1,"b":2,"c":3}

API

ss(format, [opts])

  • format is one of: 'csv', 'json', or 'ndjson'.

  • opts defaults:

{
  compact: false, // csv: will remove undefined keys (like in json)
  flatten: false // csv: will flatten nested objects using `object2dot`[1]
}

[1] object2dot

License

MIT

Current Tags

  • 1.1.0                                ...           latest (4 years ago)

2 Versions

  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 2
Dependencies (5)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |