Skip to content

Commit ead4c1f

Browse files
committed
fix: skipLines with header option. fixes #110, #84
this change integrates the proposed changes by @combizs in #111.
1 parent 65e283d commit ead4c1f

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class CsvParser extends Transform {
183183
cells.push(this._empty)
184184
}
185185

186-
const skip = this.skipLines && this.skipLines !== this._line
186+
const skip = this.skipLines && this.skipLines > this._line
187187
this._line++
188188

189189
if (this._first && !skip) {
@@ -198,7 +198,7 @@ class CsvParser extends Transform {
198198
const e = new RangeError('Row length does not match headers')
199199
this.emit('error', e)
200200
} else {
201-
if (!this._first) this._emit(this._Row, cells)
201+
if (!skip) this._emit(this._Row, cells)
202202
}
203203
}
204204

test/skipLines.test.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@ const test = require('ava')
22

33
const { collect } = require('./helpers/helper')
44

5-
test.cb('skip rows until', (t) => {
5+
test.cb('skip lines', (t) => {
66
const verify = (err, lines) => {
77
t.false(err, 'no err')
8+
t.is(lines.length, 1, '1 row')
89
t.is(JSON.stringify(lines[0]), JSON.stringify({yes: 'ok', yup: 'ok', yeah: 'ok!'}))
910
t.end()
1011
}
1112

1213
collect('junk_rows.csv', {skipLines: 2}, verify)
1314
})
15+
16+
test.cb('skip lines with headers', (t) => {
17+
const verify = (err, lines) => {
18+
t.false(err, 'no err')
19+
t.is(lines.length, 2, '2 rows')
20+
t.is(JSON.stringify(lines[0]), JSON.stringify({s: 'yes', p: 'yup', h: 'yeah'}))
21+
t.is(JSON.stringify(lines[1]), JSON.stringify({s: 'ok', p: 'ok', h: 'ok!'}))
22+
t.end()
23+
}
24+
25+
collect('junk_rows.csv', {headers: ['s', 'p', 'h'], skipLines: 2}, verify)
26+
})

0 commit comments

Comments
 (0)