Skip to content

Commit 4ee35cd

Browse files
Victor Andréeshellscape
authored andcommitted
fix: map final empty value. fixes #124 (#125)
1 parent 7dc3acc commit 4ee35cd

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class CsvParser extends Transform {
180180
}
181181

182182
if (buf[end - 1] === comma) {
183-
cells.push(this._empty)
183+
cells.push(mapValue(this._empty))
184184
}
185185

186186
const skip = this.skipLines && this.skipLines > this._line

test/mapValues.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,19 @@ test.cb('map values', (t) => {
2222

2323
collect('dummy.csv', { mapValues }, verify)
2424
})
25+
26+
test.cb('map last empty value', (t) => {
27+
const mapValues = ({ value }) => {
28+
return value === '' ? null : value
29+
}
30+
31+
const verify = (err, lines) => {
32+
t.false(err, 'no err')
33+
t.is(lines.length, 2, '2 rows')
34+
t.is(lines[0]['name'], null, 'name is mapped')
35+
t.is(lines[0]['location'], null, 'last value mapped')
36+
t.end()
37+
}
38+
39+
collect('empty_columns.csv', { mapValues, headers: ['date', 'name', 'location'] }, verify)
40+
})

0 commit comments

Comments
 (0)