Skip to content

Commit

Permalink
Escape cells with commas in the value
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiak committed Jul 15, 2019
1 parent 589a9a8 commit 30df82c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ const createStreamWriter = (outputPath, columns) => {
writer.write(`${columns.join(',')}\n`)

return data => {
var values = []
const values = []

columns.forEach(col => {
values.push(data[col])
columns.forEach((col, colIndex) => {
const value = data[col]

// handle cases where there is a comma in the cell's value
if (value && value.includes(',')) {
values.push(`"${data[col]}"`)
return
}

values.push(data[col])
})

writer.write(`${values.join(',')}\n`)
Expand Down

0 comments on commit 30df82c

Please sign in to comment.