Comparing version 0.1.1 to 1.0.0
{ | ||
"name": "json-csv", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "Export a richly structured, JSON array to CSV", | ||
@@ -21,3 +21,3 @@ "homepage": "https://github.com/IWSLLC/json-csv", | ||
], | ||
"main": "./json-csv.js", | ||
"main": "./index.js", | ||
"engines": { | ||
@@ -27,4 +27,6 @@ "node": "*" | ||
"devDependencies": { | ||
"mocha": "latest", | ||
"should": "latest" | ||
"coffee-script": "^1.7.1", | ||
"concat-stream": "^1.4.6", | ||
"mocha": "^1.20.1", | ||
"should": "^4.0.4" | ||
}, | ||
@@ -38,2 +40,5 @@ "bugs": { | ||
"dependencies": { | ||
"concat-stream": "^1.4.6", | ||
"event-stream": "^3.1.7", | ||
"lodash": "^2.4.1" | ||
}, | ||
@@ -40,0 +45,0 @@ "scripts": { |
json-csv | ||
======== | ||
![Build status](https://travis-ci.org/IWSLLC/json-csv.svg?branch=master) | ||
Simple CSV export module that can export a rich JSON array of objects to CSV. | ||
@@ -8,6 +10,12 @@ | ||
----- | ||
###Buffered### | ||
``` | ||
var csv = require('json-csv') | ||
csv.toCSV(args, callback) | ||
var jsoncsv = require('json-csv') | ||
jsoncsv.csvBuffered(data, options, callback) | ||
``` | ||
- data : Array of JS objects | ||
- callback : returns buffered result (see below) | ||
``` | ||
var callback = function(err,csv) { | ||
@@ -18,20 +26,18 @@ //csv contains string of converted data in CSV format. | ||
Streaming | ||
--------- | ||
###Streaming### | ||
When using the streaming API, you'll need to also stream data into it. | ||
``` | ||
var csv = require('json-csv') | ||
var reader = csv.createReadStream(args) | ||
reader.on('end', function() { | ||
//all done | ||
}) | ||
reader.pipe(something_writable) | ||
var jsoncsv = require('json-csv') | ||
var readable_source = <something readable that emits data row by row> | ||
readable_source | ||
.pipe(jsoncsv.csv(options)) | ||
.pipe(something_else_writable) | ||
``` | ||
Arguments: | ||
###Options### | ||
``` | ||
{ | ||
//required: array of data | ||
data : [], | ||
//field definitions for CSV export | ||
@@ -59,3 +65,3 @@ fields : | ||
``` | ||
var csv = require('../json-csv') | ||
var jsoncsv = require('../json-csv') | ||
var items = [ | ||
@@ -83,3 +89,3 @@ { | ||
csv.toCSV({ | ||
jsoncsv.csvBuffered({ | ||
data : items, | ||
@@ -106,4 +112,3 @@ fields : [ | ||
//OR Streaming | ||
csv.createReadStream({ | ||
data : items, | ||
var options = { | ||
fields : [ | ||
@@ -123,7 +128,11 @@ { | ||
} | ||
]}).pipe(process.stdout); | ||
]} | ||
var source = es.readArray(items) | ||
source | ||
.pipe(jsoncsv.csv(options)) | ||
.pipe(process.stdout) | ||
``` | ||
Generates Output: | ||
``` output | ||
``` | ||
Name,Email,Amount | ||
@@ -139,3 +148,3 @@ "fred",fred@somewhere,1.02 | ||
``` | ||
var csv = require('json-csv') | ||
var jsoncsv = require('json-csv') | ||
var items = [ | ||
@@ -166,4 +175,3 @@ { | ||
csv.toCSV({ | ||
data : items, | ||
jsoncsv.csvBuffered(items, { | ||
fields : [ | ||
@@ -205,3 +213,3 @@ { | ||
Generates Output: | ||
``` output | ||
``` | ||
Company,Name,Email,Year,Level | ||
@@ -215,5 +223,5 @@ "Widgets, LLC",John Doe,john@widgets.somewhere,2013,Unknown | ||
var fs = require("fs") | ||
var out = fs.createWriteStream("output.csv", {encoding: 'utf8'}) | ||
var reader = csv.createReadStream({ | ||
data : items, | ||
var es = require("event-stream") | ||
var options = { | ||
fields : [ | ||
@@ -247,8 +255,8 @@ { | ||
}] | ||
}) | ||
reader.on('end', function() { | ||
console.log("done") | ||
}) | ||
reader.pipe(out) | ||
} | ||
var out = fs.createWriteStream("output.csv", {encoding: 'utf8'}) | ||
var readable = es.readArray(items) | ||
readable | ||
.pipe(jsoncsv.csv(options)) | ||
.pipe(out) | ||
``` |
@@ -1,2 +0,2 @@ | ||
var csv = require('../json-csv') | ||
var csv = require('../index') | ||
var items = [ | ||
@@ -29,5 +29,4 @@ { | ||
csv.toCSV({ | ||
data : items, | ||
fields : [ | ||
csv.csvBuffered(items, { | ||
fields : [ | ||
{ | ||
@@ -49,3 +48,3 @@ name : 'contact.company', | ||
}, | ||
{ | ||
{ | ||
name : 'registration.level', | ||
@@ -64,2 +63,2 @@ label : 'Level', | ||
console.log(csv); | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
var csv = require('../json-csv') | ||
var csv = require('../index') | ||
var items = [ | ||
@@ -24,5 +24,4 @@ { | ||
csv.toCSV({ | ||
data : items, | ||
fields : [ | ||
csv.csvBuffered(items, { | ||
fields : [ | ||
{ | ||
@@ -44,2 +43,2 @@ name : 'name', | ||
console.log(csv); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
17381
13
301
0
252
3
4
1
+ Addedconcat-stream@^1.4.6
+ Addedevent-stream@^3.1.7
+ Addedlodash@^2.4.1
+ Addedbuffer-from@1.1.2(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedduplexer@0.1.2(transitive)
+ Addedevent-stream@3.3.5(transitive)
+ Addedfrom@0.1.7(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedlodash@2.4.2(transitive)
+ Addedmap-stream@0.0.7(transitive)
+ Addedpause-stream@0.0.11(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsplit@1.0.1(transitive)
+ Addedstream-combiner@0.2.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addedutil-deprecate@1.0.2(transitive)