json-to-csv-stream
Advanced tools
Comparing version 1.0.0 to 1.1.0
14
index.js
@@ -10,11 +10,17 @@ 'use strict' | ||
function JSONToCsv () { | ||
return pumpify(JSONStream.parse(), split(), CsvStream()) | ||
function JSONToCsv (options) { | ||
options = options || {} | ||
return pumpify( | ||
JSONStream.parse(options.path), | ||
split(), | ||
CsvStream(options.csv) | ||
) | ||
} | ||
function split () { | ||
return through.obj(function (array, enc, callback) { | ||
array.forEach(this.push.bind(this)) | ||
return through.obj(function (chunk, enc, callback) { | ||
if (Array.isArray(chunk)) chunk.forEach(this.push.bind(this)) | ||
else this.push(chunk) | ||
callback(null) | ||
}) | ||
} |
{ | ||
"name": "json-to-csv-stream", | ||
"main": "index.js", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Convert a JSON array stream into CSV rows", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
@@ -24,4 +24,27 @@ # json-to-csv-stream [![Build Status](https://travis-ci.org/bendrucker/json-to-csv-stream.svg?branch=master)](https://travis-ci.org/bendrucker/json-to-csv-stream) | ||
## API | ||
#### `jsonToCsvStream(options)` -> `Transform` | ||
##### options | ||
Type: `object` | ||
Default: `{}` | ||
###### path | ||
Type: `any` | ||
Default: `undefined` | ||
A path for [`JSONStream.parse`](https://github.com/dominictarr/JSONStream#jsonstreamparsepath). | ||
###### csv | ||
Type: `object` | ||
Default: `undefined` | ||
Options to pass to [`csv-write-stream`](https://github.com/maxogden/csv-write-stream#var-writer--csvwriteroptions). | ||
## License | ||
MIT © [Ben Drucker](http://bendrucker.me) |
3332
21
50