d0f8cd9e78
refs https://github.com/TryGhost/Ghost/pull/11539 - The script helps to migrate CSV exports from Substack to Ghost-compatible ones
23 lines
507 B
JavaScript
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;
|
|
};
|