New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

json-csv

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-csv - npm Package Compare versions

Comparing version 0.1.1 to 1.0.0

.travis.yml

13

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc