json-2-csv
Advanced tools
Comparing version 1.2.0 to 1.2.1
{ | ||
"name": "json-2-csv", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"homepage": "https://github.com/mrodrig/json-2-csv", | ||
@@ -5,0 +5,0 @@ "moduleType": [ |
@@ -29,2 +29,3 @@ { | ||
"EOL" : "\n", | ||
"PREPEND_HEADER" : true, | ||
"PARSE_CSV_NUMBERS" : false, | ||
@@ -31,0 +32,0 @@ "KEYS" : null |
@@ -149,3 +149,4 @@ 'use strict'; | ||
.spread(function (csvHeading, csvData) { | ||
if (options.DELIMITER.WRAP) { | ||
// If the fields are supposed to be wrapped... (only perform this if we are actually prepending the header) | ||
if (options.DELIMITER.WRAP && options.PREPEND_HEADER) { | ||
csvHeading = _.map(csvHeading, function(headingKey) { | ||
@@ -155,4 +156,9 @@ return options.DELIMITER.WRAP + headingKey + options.DELIMITER.WRAP; | ||
} | ||
csvHeading = csvHeading.join(options.DELIMITER.FIELD); | ||
return callback(null, [csvHeading, csvData].join(options.EOL)); | ||
// If we are prepending the header, then join the csvHeading fields | ||
if (options.PREPEND_HEADER) { | ||
csvHeading = csvHeading.join(options.DELIMITER.FIELD); | ||
} | ||
// If we are prepending the header, then join the header and data by EOL, otherwise just return the data | ||
return callback(null, options.PREPEND_HEADER ? csvHeading + options.EOL + csvData : csvData); | ||
}) | ||
@@ -159,0 +165,0 @@ .catch(function (err) { |
@@ -5,3 +5,3 @@ { | ||
"description": "A JSON to CSV and CSV to JSON converter that natively supports sub-documents and auto-generates the CSV heading.", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -37,2 +37,3 @@ # Convert JSON to CSV or CSV to JSON | ||
* `WRAP` - String - Wrap values in the delimiter of choice (e.g. wrap values in quotes). Default: `''` | ||
* `PREPEND_HEADER` - Boolean - Should the auto-generated header be prepended as the first line in the CSV? Default: `true` | ||
* `EOL` - String - End of Line Delimiter. Default: `'\n'` | ||
@@ -39,0 +40,0 @@ * `KEYS` - Array - Specify the keys (as strings) that should be converted. Default: `null` |
48
test.js
@@ -1,4 +0,1 @@ | ||
/** | ||
* Created by mrodrigues on 2/17/15. | ||
*/ | ||
var Promise = require('bluebird'), | ||
@@ -32,18 +29,19 @@ converter = Promise.promisifyAll(require('./lib/converter')); | ||
//converter.json2csv(documents, function (err, csv) { | ||
// if (!err) { | ||
// return console.log('csv', csv); | ||
// } | ||
// return console.log('err', err); | ||
// }, | ||
// { | ||
// DELIMITER : { | ||
// FIELD : ',', | ||
// ARRAY : '/', | ||
// WRAP : '\"' | ||
// }, | ||
// EOL : '\n', | ||
// PARSE_CSV_NUMBERS : false, | ||
// KEYS: ['Make', 'Model', 'Specifications.Mileage'] | ||
// }); | ||
converter.json2csv(documents, function (err, csv) { | ||
if (!err) { | ||
return console.log('csv', csv); | ||
} | ||
return console.log('err', err); | ||
}, | ||
{ | ||
DELIMITER : { | ||
FIELD : ',', | ||
ARRAY : '/', | ||
WRAP : '\"' | ||
}, | ||
EOL : '\n', | ||
PREPEND_HEADER : false, | ||
PARSE_CSV_NUMBERS : false, | ||
KEYS: ['Make', 'Model', 'Specifications.Mileage'] | ||
}); | ||
@@ -58,8 +56,8 @@ //converter.json2csvAsync(documents, {}) | ||
converter.csv2json(csv, function (err, json) { | ||
if (!err) { | ||
return console.log('json', json); | ||
} | ||
return console.log('err', err); | ||
}, {KEYS: ['Model', 'Specifications.Mileage']}); | ||
//converter.csv2json(csv, function (err, json) { | ||
// if (!err) { | ||
// return console.log('json', json); | ||
// } | ||
// return console.log('err', err); | ||
//}, {KEYS: ['Model', 'Specifications.Mileage']}); | ||
@@ -66,0 +64,0 @@ //converter.csv2jsonAsync(csv, {}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
222561
37
822
226
0