Skip to content

Commit

Permalink
fix(reducer-gtfsplus): fix column parsing for gtfsplus csv
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed Mar 14, 2017
1 parent 46b3c9a commit 23c4f00
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/gtfsplus/reducers/gtfsplus.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ const gtfsplus = (state = {
case 'RECEIVE_GTFSPLUS_CONTENT':
const newTableData = {}
for (let i = 0; i < action.filenames.length; i++) {
// split file into lines
const lines = action.fileContent[i].split(/\r\n|\r|\n/g)
if (lines.length < 2) continue
// console.log(lines[0])
const fields = lines[0].split(',')
// console.log(fields)
// console.log(fields[fields.length - 1])
const COLUMN_REGEX = /,(?=(?:(?:[^"]*"){2})*[^"]*$)/
const tableName = action.filenames[i].split('.')[0]
newTableData[tableName] = lines.slice(1)
.filter(line => line.split(',').length === fields.length)
.filter(line => line.split(COLUMN_REGEX).length === fields.length)
.map((line, rowIndex) => {
const values = line.split(',')
const values = line.split(COLUMN_REGEX)
const rowData = { origRowIndex: rowIndex }
for (let f = 0; f < fields.length; f++) {
rowData[fields[f]] = values[f]
Expand Down

0 comments on commit 23c4f00

Please sign in to comment.