0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-25 02:31:59 -05:00

Substituted csv-parser with papaparse as CSV parsing package

refs 5c46786ebc

- This is continuation of work removing csv-parser as main CSV handling library with more suitable papaparse library
- Referenced commit introduced papaparse as a library to serialize JSON to CSV, this changeset takes it a step further and replaces CSV to JSON seriazliation logic
This commit is contained in:
Nazar Gargol 2020-07-08 19:39:37 +12:00
parent 587c95b0d0
commit 3a97d39d72
3 changed files with 16 additions and 4 deletions
ghost/members-csv

View file

@ -1,5 +1,5 @@
const Promise = require('bluebird');
const csvParser = require('csv-parser');
const papaparse = require('papaparse');
const _ = require('lodash');
const fs = require('fs-extra');
@ -63,7 +63,9 @@ const readCSV = ({path, columnsToExtract, mapping}) => {
readFile.on('err', function (err) {
reject(err);
})
.pipe(csvParser())
.pipe(papaparse.parse(papaparse.NODE_STREAM_INPUT, {
header: true
}))
.on('data', function (row) {
rows.push(row);
})

View file

@ -24,7 +24,6 @@
"sinon": "9.0.2"
},
"dependencies": {
"csv-parser": "2.3.3",
"papaparse": "5.2.0"
}
}

View file

@ -3,7 +3,17 @@ const path = require('path');
const {readCSV} = require('../lib/parse');
const csvPath = path.join(__dirname, '/fixtures/');
describe('read csv', function () {
describe('parse', function () {
it('read csv: empty file', async function () {
const result = await readCSV({
path: csvPath + 'empty.csv',
columnsToExtract: [{name: 'email', lookup: /email/i}]
});
should.exist(result);
result.length.should.eql(0);
});
it('read csv: one column', async function () {
const result = await readCSV({
path: csvPath + 'single-column-with-header.csv',
@ -85,6 +95,7 @@ describe('read csv', function () {
result[1].nombre.should.eql('test');
result[1].id.should.eql('2');
});
it('read csv: two columns with empty mapping', async function () {
const result = await readCSV({
path: csvPath + 'two-columns-mapping-header.csv',