Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements #360

Merged
merged 13 commits into from
Mar 10, 2019
Prev Previous commit
Next Next commit
Improve fields gathering
juanjoDiaz committed Feb 24, 2019

Verified

This commit was signed with the committer’s verified signature.
sdispater Sébastien Eustace
commit 7aa5676666ce578d06322f99bc2e980bf8d64f98
14 changes: 9 additions & 5 deletions lib/JSON2CSVParser.js
Original file line number Diff line number Diff line change
@@ -13,12 +13,16 @@ class JSON2CSVParser extends JSON2CSVBase {
const processedData = this.preprocessData(data);

if (!this.opts.fields) {
const dataFields = processedData
.map(item => Object.keys(item))
.reduce((tempData, rows) => tempData.concat(rows), []);
this.opts.fields = processedData
.reduce((fields, item) => {
Object.keys(item).forEach((field) => {
if (!fields.includes(field)) {
fields.push(field)
}
});

this.opts.fields = dataFields
.filter((field, pos, arr) => arr.indexOf(field) == pos);
return fields
}, []);
}

this.opts.fields = this.preprocessFieldsInfo(this.opts.fields);