Ghost/core/server/lib/fs/format-csv.js
Rish 4eeed0d32a 🐛 Fixed "undefined" values in member csv export
no issue

We missed handling `undefined` values for fields during csv export for memebrs, which causes csv entries as `undefined` for fields that don't exist. It also added need for extra handling of `undefined` entries during csv import. This PR fixes the bug by properly handling empty/undefined values in export
2020-02-12 11:03:16 +05:30

23 lines
539 B
JavaScript

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;
};