mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Removed format-csv module in favor of papaparse
no issue - The aim was to extract format-csv to become an external dependency. After some analysis found out that native papaparse method `unparse` was achieving the same results with a lot better test coverage and stability. Because papaparse will become Ghost's default csv processor in near future decided to integrate papaparse instead of extracting module for the format-csv module's code, which would become redundant soon anyways. - For reference papaparse will substitute current csv-parser lib because it's better performance and maturity. - Performance comparison can be checked here - https://github.com/Keyang/csvbench#result . At the time of writing papaparse is rougly 40% faster than csv-parser
This commit is contained in:
parent
d44dae0c79
commit
53abf79869
5 changed files with 11 additions and 31 deletions
|
@ -3,7 +3,7 @@ const {i18n} = require('../../../../../lib/common');
|
||||||
const errors = require('@tryghost/errors');
|
const errors = require('@tryghost/errors');
|
||||||
const debug = require('ghost-ignition').debug('api:canary:utils:serializers:output:members');
|
const debug = require('ghost-ignition').debug('api:canary:utils:serializers:output:members');
|
||||||
const mapper = require('./utils/mapper');
|
const mapper = require('./utils/mapper');
|
||||||
const {formatCSV} = require('../../../../../lib/fs');
|
const papaparse = require('papaparse');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
browse(data, apiConfig, frame) {
|
browse(data, apiConfig, frame) {
|
||||||
|
@ -70,7 +70,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
let labels = [];
|
let labels = [];
|
||||||
if (member.labels) {
|
if (member.labels) {
|
||||||
labels = `"${member.labels.map(l => l.name).join(',')}"`;
|
labels = `${member.labels.map(l => l.name).join(',')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -81,13 +81,13 @@ module.exports = {
|
||||||
subscribed_to_emails: member.subscribed,
|
subscribed_to_emails: member.subscribed,
|
||||||
complimentary_plan: member.comped,
|
complimentary_plan: member.comped,
|
||||||
stripe_customer_id: stripeCustomerId,
|
stripe_customer_id: stripeCustomerId,
|
||||||
created_at: JSON.stringify(member.created_at),
|
created_at: member.created_at,
|
||||||
deleted_at: JSON.stringify(member.deleted_at),
|
deleted_at: member.deleted_at,
|
||||||
labels: labels
|
labels: labels
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
frame.response = formatCSV(members, fields);
|
frame.response = papaparse.unparse(members);
|
||||||
},
|
},
|
||||||
|
|
||||||
importCSV(data, apiConfig, frame) {
|
importCSV(data, apiConfig, frame) {
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
module.exports = function formatCSV(data, fields) {
|
|
||||||
let csv = `${fields.join(',')}\r\n`;
|
|
||||||
let entry;
|
|
||||||
let field;
|
|
||||||
let j;
|
|
||||||
let i;
|
|
||||||
|
|
||||||
for (j = 0; j < data.length; j = j + 1) {
|
|
||||||
entry = data[j];
|
|
||||||
|
|
||||||
for (i = 0; i < fields.length; i = i + 1) {
|
|
||||||
field = fields[i];
|
|
||||||
csv += (entry[field] !== null && entry[field] !== undefined) ? entry[field] : '';
|
|
||||||
if (i !== fields.length - 1) {
|
|
||||||
csv += ',';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
csv += '\r\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
return csv;
|
|
||||||
};
|
|
|
@ -1,9 +1,5 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
get readCSV() {
|
get readCSV() {
|
||||||
return require('./read-csv');
|
return require('./read-csv');
|
||||||
},
|
|
||||||
|
|
||||||
get formatCSV() {
|
|
||||||
return require('./format-csv');
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -121,6 +121,7 @@
|
||||||
"node-jose": "1.1.4",
|
"node-jose": "1.1.4",
|
||||||
"nodemailer": "0.7.1",
|
"nodemailer": "0.7.1",
|
||||||
"oembed-parser": "1.3.7",
|
"oembed-parser": "1.3.7",
|
||||||
|
"papaparse": "5.2.0",
|
||||||
"path-match": "1.2.4",
|
"path-match": "1.2.4",
|
||||||
"probe-image-size": "5.0.0",
|
"probe-image-size": "5.0.0",
|
||||||
"rss": "1.2.2",
|
"rss": "1.2.2",
|
||||||
|
|
|
@ -7017,6 +7017,11 @@ pako@~1.0.5:
|
||||||
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
|
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.11.tgz#6c9599d340d54dfd3946380252a35705a6b992bf"
|
||||||
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
|
integrity sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==
|
||||||
|
|
||||||
|
papaparse@5.2.0:
|
||||||
|
version "5.2.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/papaparse/-/papaparse-5.2.0.tgz#97976a1b135c46612773029153dc64995caa3b7b"
|
||||||
|
integrity sha512-ylq1wgUSnagU+MKQtNeVqrPhZuMYBvOSL00DHycFTCxownF95gpLAk1HiHdUW77N8yxRq1qHXLdlIPyBSG9NSA==
|
||||||
|
|
||||||
parent-module@^1.0.0:
|
parent-module@^1.0.0:
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"
|
resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"
|
||||||
|
|
Loading…
Add table
Reference in a new issue