node-csv-parse
node-csv-parse copied to clipboard
skip_empty_lines property is not working as expected
skip_empty_lines : Don't generate records for empty lines (line matching /\s*/), defaults to false.
As per the above definition it should ignore a row if it contains any string matching the regex '/\s*/'. But when a row contains a space or tab in it, its not skipping the row and I am encountering following error CsvError: Invalid Record Length: expect 2, got 1 on line 2
As a work around I have set trim as true and then it works. Am I doing something wrong here or is it an issue?
const parse = require('csv-parse')
const assert = require('assert')
parse(`
"key_1","key_2"\n\t\n"value 1","value 2"
`.trim(), {
// trim: true,
columns: false,
skip_empty_lines: true
}, (err, records) => {
if (err) {
console.log('******', err)
}
assert.deepStrictEqual(
records, [
[
'key_1',
'key_2'
],
[
'value 1',
'value 2'
]]
)
})
Could you edit you issue with a valid markdown syntax using triple backticks, thank you
The doc is wrong. In the current implementation, by "empty", we really mean empty, no spaces, no tabs. Let me see if I can do sth about it
You can combine skip_lines_with_empty_values
and relax_column_count
. Would that works for you ? I'll fix the doc
My use-case here is to ignore the second row which had tab space in it. By enabling 'relax_column_count' I wont get an error if column count doesn't match with header count which is not desirable for us.
Then your solution with trim
shall be appropriate.