mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 01:41:46 +03:00
4eeed0d32a
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
23 lines
539 B
JavaScript
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;
|
|
};
|