Ghost/ghost/substack-ghost-csv-converter/lib/format-csv.js
Naz Gargol d0f8cd9e78 Added Substack to Ghost CSV converter package (#121)
refs https://github.com/TryGhost/Ghost/pull/11539

- The script helps to migrate CSV exports from Substack to Ghost-compatible ones
2020-02-04 14:03:29 +08:00

23 lines
507 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] : '';
if (i !== fields.length - 1) {
csv += ',';
}
}
csv += '\r\n';
}
return csv;
};