0.0.0 • Published 9 years ago

ldjson-keys v0.0.0

Weekly downloads
1
License
AGPL-3.0
Repository
github
Last release
9 years ago

#ldjson-keys

Pipe LDJSON in, get all of the keys found out.

This is useful in conjunction with maxogden/csv-write-stream that reads CSV columns from first row/object only.

Build Status Dependencies License

##Run

Install with npm.

$ npm install ldjson-to-csv -g

By default you get new-line delimited output:

$ echo '{"col1":1}\n{"col2":2}' | ldjson-to-csv
# col1
# col2

##Source

_       = require 'highland'
ndjson  = require 'ndjson'
{ EOL } = require 'os'

module.exports = ->
  keys = {}

  through = (obj) ->
    _ (push, next) ->
      for k of obj when k not of keys
        keys[k] = null
        push null, k + EOL
      push null, _.nil

  _.pipeline.apply _, [
    do _
    do ndjson.parse
    _.map through
    _.parallel 50
  ]