jsonexport
Advanced tools
Comparing version 2.0.4 to 2.0.6
@@ -40,3 +40,3 @@ /* jshint node:true */ | ||
let headers = this._headers; | ||
if(this._options.rename && this._options.rename.length > 0) | ||
if (this._options.rename && this._options.rename.length > 0) | ||
headers = headers.map((header) => this._options.rename[this._options.headers.indexOf(header)] || header) | ||
@@ -54,3 +54,3 @@ return headers.join(this._options.rowDelimiter); | ||
let getHeaderIndex = function(header) { | ||
let index = self._headers.indexOf(header); | ||
var index = self._headers.indexOf(header); | ||
if (index === -1) { | ||
@@ -69,6 +69,6 @@ self._headers.push(header); | ||
let rows = [Array(self._headers.length).join(".").split(".")]; | ||
for(let element of result){ | ||
for (let element of result) { | ||
let elementHeaderIndex = getHeaderIndex(element.item); | ||
let placed = false; | ||
for(let row of rows){ | ||
for (let row of rows) { | ||
if (!placed && row[elementHeaderIndex] === '' || row[elementHeaderIndex] === undefined) { | ||
@@ -87,6 +87,6 @@ row[elementHeaderIndex] = self._escape(element.value); | ||
let lastRow = null; | ||
for(let row of rows){ | ||
for (let row of rows) { | ||
let missing = self._headers.length - row.length; | ||
if(missing > 0) row = row.concat(Array(missing).join(".").split(".")); | ||
if(lastRow && self._options.fillGaps) row = row.map((col, index) => col === '' || col === undefined ? lastRow[index] : col); | ||
if (missing > 0) row = row.concat(Array(missing).join(".").split(".")); | ||
if (lastRow && self._options.fillGaps) row = row.map((col, index) => col === '' || col === undefined ? lastRow[index] : col); | ||
fileRows.push(row.join(self._options.rowDelimiter)); | ||
@@ -96,3 +96,3 @@ lastRow = row; | ||
}; | ||
for(let item of json){ | ||
for (let item of json) { | ||
//Call checkType to list all items inside this object | ||
@@ -244,25 +244,18 @@ //Items are returned as a object {item: 'Prop Value, Item Name', | ||
let result = []; | ||
for(let element of array){ | ||
var firstElementWithoutItem; | ||
for (let element of array) { | ||
//Check the propData type | ||
var resultCheckType = self._checkType(element); | ||
//Check for results without itens, merge all itens with the first occurrence | ||
if(resultCheckType.length === 0) continue; | ||
var firstResult = resultCheckType[0]; | ||
if (!firstResult.item && firstElementWithoutItem !== undefined) { | ||
firstElementWithoutItem.value += self._options.arrayPathString + firstResult.value; | ||
continue; | ||
} else if (resultCheckType.length > 0 && !firstResult.item && firstElementWithoutItem === undefined) { | ||
firstElementWithoutItem = firstResult; | ||
} | ||
//Append to results | ||
result = result.concat(resultCheckType); | ||
} | ||
//Check for results without itens, merge all itens with the first occurrence | ||
var firstElementWithoutItem; | ||
result = result.filter(function(resultElement, resultIndex) { | ||
//Check if there is a firstElement and if the current element dont have a item | ||
if (!resultElement.item && firstElementWithoutItem !== undefined) { | ||
//Append the value to the firstElementWithoutItem. | ||
result[firstElementWithoutItem].value += self._options.arrayPathString + resultElement.value; | ||
//Remove the item | ||
return false; | ||
} | ||
//Set the firstElement if its not set | ||
if (!firstElementWithoutItem && !resultElement.item) | ||
firstElementWithoutItem = resultIndex; | ||
//Keep the item in the array | ||
return true; | ||
}); | ||
return result; | ||
@@ -325,4 +318,4 @@ } | ||
let defaultOptions = { | ||
headers: [],// Array | ||
rename: [],// Array | ||
headers: [], // Array | ||
rename: [], // Array | ||
headerPathString: '.', // String | ||
@@ -329,0 +322,0 @@ rowDelimiter: ',', // String |
{ | ||
"name": "jsonexport", | ||
"version": "2.0.0", | ||
"version": "2.0.4", | ||
"lockfileVersion": 1, | ||
@@ -11,2 +11,8 @@ "dependencies": { | ||
}, | ||
"async": { | ||
"version": "0.2.10", | ||
"resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz", | ||
"integrity": "sha1-trvgsGdLnXGXCMo43owjfLUmw9E=", | ||
"dev": true | ||
}, | ||
"balanced-match": { | ||
@@ -17,2 +23,16 @@ "version": "https://registry.npmjs.org/balanced-match/-/balanced-match-0.4.2.tgz", | ||
}, | ||
"benchmark": { | ||
"version": "2.1.4", | ||
"resolved": "https://registry.npmjs.org/benchmark/-/benchmark-2.1.4.tgz", | ||
"integrity": "sha1-CfPeMckWQl1JjMLuVloOvzwqVik=", | ||
"dev": true, | ||
"dependencies": { | ||
"lodash": { | ||
"version": "4.17.4", | ||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", | ||
"integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=", | ||
"dev": true | ||
} | ||
} | ||
}, | ||
"brace-expansion": { | ||
@@ -67,2 +87,14 @@ "version": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.7.tgz", | ||
}, | ||
"cli-table": { | ||
"version": "0.3.1", | ||
"resolved": "https://registry.npmjs.org/cli-table/-/cli-table-0.3.1.tgz", | ||
"integrity": "sha1-9TsFJmqLGguTSz0IIebi3FkUriM=", | ||
"dev": true | ||
}, | ||
"colors": { | ||
"version": "1.0.3", | ||
"resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz", | ||
"integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=", | ||
"dev": true | ||
}, | ||
"commander": { | ||
@@ -150,2 +182,8 @@ "version": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz", | ||
}, | ||
"flat": { | ||
"version": "2.0.1", | ||
"resolved": "https://registry.npmjs.org/flat/-/flat-2.0.1.tgz", | ||
"integrity": "sha1-cOKRiKdL4MPIlAnu0fqVd5B64y8=", | ||
"dev": true | ||
}, | ||
"fs.realpath": { | ||
@@ -197,2 +235,8 @@ "version": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", | ||
}, | ||
"is-buffer": { | ||
"version": "1.1.5", | ||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.5.tgz", | ||
"integrity": "sha1-Hzsm72E7IUuIy8ojzGwB2Hlh7sw=", | ||
"dev": true | ||
}, | ||
"isarray": { | ||
@@ -208,2 +252,23 @@ "version": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", | ||
}, | ||
"json2csv": { | ||
"version": "3.7.3", | ||
"resolved": "https://registry.npmjs.org/json2csv/-/json2csv-3.7.3.tgz", | ||
"integrity": "sha1-2s/fp/sMGxsWOGjcdfOQLQIzVOw=", | ||
"dev": true | ||
}, | ||
"json2csv-stream": { | ||
"version": "0.1.4", | ||
"resolved": "https://registry.npmjs.org/json2csv-stream/-/json2csv-stream-0.1.4.tgz", | ||
"integrity": "sha1-TQuhnzK6AOaaYJgeId7EMpxuDmc=", | ||
"dev": true, | ||
"dependencies": { | ||
"readable-stream": { | ||
"version": "1.0.34", | ||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz", | ||
"integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=", | ||
"dev": true, | ||
"optional": true | ||
} | ||
} | ||
}, | ||
"json3": { | ||
@@ -244,2 +309,8 @@ "version": "https://registry.npmjs.org/json3/-/json3-3.3.2.tgz", | ||
}, | ||
"lodash.clonedeep": { | ||
"version": "4.5.0", | ||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", | ||
"integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=", | ||
"dev": true | ||
}, | ||
"lodash.create": { | ||
@@ -250,2 +321,14 @@ "version": "https://registry.npmjs.org/lodash.create/-/lodash.create-3.1.1.tgz", | ||
}, | ||
"lodash.flatten": { | ||
"version": "4.4.0", | ||
"resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz", | ||
"integrity": "sha1-8xwiIlqWMtK7+OSt2+8kCqdlph8=", | ||
"dev": true | ||
}, | ||
"lodash.get": { | ||
"version": "4.4.2", | ||
"resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", | ||
"integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", | ||
"dev": true | ||
}, | ||
"lodash.isarguments": { | ||
@@ -266,2 +349,14 @@ "version": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz", | ||
}, | ||
"lodash.set": { | ||
"version": "4.3.2", | ||
"resolved": "https://registry.npmjs.org/lodash.set/-/lodash.set-4.3.2.tgz", | ||
"integrity": "sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM=", | ||
"dev": true | ||
}, | ||
"lodash.uniq": { | ||
"version": "4.5.0", | ||
"resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz", | ||
"integrity": "sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=", | ||
"dev": true | ||
}, | ||
"minimatch": { | ||
@@ -315,2 +410,8 @@ "version": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", | ||
}, | ||
"platform": { | ||
"version": "1.3.4", | ||
"resolved": "https://registry.npmjs.org/platform/-/platform-1.3.4.tgz", | ||
"integrity": "sha1-bw+xftqqSPIUQrOpdcBjEw8cPr0=", | ||
"dev": true | ||
}, | ||
"readable-stream": { | ||
@@ -317,0 +418,0 @@ "version": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.1.14.tgz", |
{ | ||
"name": "jsonexport", | ||
"version": "2.0.4", | ||
"version": "2.0.6", | ||
"description": "Makes easy to convert JSON to CSV", | ||
@@ -45,2 +45,3 @@ "main": "./lib", | ||
"devDependencies": { | ||
"benchmark": "^2.1.4", | ||
"chai": "^4.0.1", | ||
@@ -47,0 +48,0 @@ "jshint": "^2.9.4", |
@@ -17,16 +17,2 @@ # jsonexport | ||
Changelog | ||
---------------------- | ||
- v2.0.0 - stream support + new line fix + remove orderHeaders option + new headers option | ||
- v1.5.0 - escaping content in headers / arrays (papswell) | ||
- v1.4.2 - default date handler return date.toLocaleString (jclay) | ||
- v1.3.2 - fix userOptions optional | ||
- v1.3.1 - object & array test | ||
- v1.3.0 - some bug fixes + mocha tests/ + removed options handleArray and handleObject | ||
- v1.2.2 - special chars escaping improvement (papswell) | ||
- v1.2.0 - orderHeaders defaults to false | ||
- v1.1.2 - Escaping text content if needed (papswell) | ||
- v1.1.0 - Expose library as CLI (cburgmer) | ||
- v1.0.7 - Fix for prototyped properties | ||
- v1.0.6 - Create new lines in the CSV file to handle JSON objects with arrays | ||
@@ -220,2 +206,3 @@ # Usage | ||
- `headers` - `Array` Used to set a custom header order, defaults to `[]` example `['lastname', 'name']` | ||
- `rename` - `Array` Used to set a custom header text, defaults to `[]` example `['Last Name', 'Name']` | ||
- `rowDelimiter` - `String` Change the file row delimiter | ||
@@ -222,0 +209,0 @@ - Defaults to `,` (**cvs format**). |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
2485
10572735
4
249
2
1