CSVParse for Node.js

IssuesGitHub

Option skip_empty_lines

Table of Contents

The skip_empty_lines skips any line which is empty.

Example

The option.skip_empty_line.js option example activates the option by setting its value to true:

const parse = require('csv-parse/lib/sync')
const assert = require('assert')

const records = parse(`
"a","b","c"

"d","e","f"
`, {
  skip_empty_lines: true
})

assert.deepEqual(
  records, [
    ['a', 'b', 'c'],
    ['d', 'e', 'f']
  ]
)

Whitespace characters

The line must be completely empty, without any characters including spaces and tabs. If you happens to have such characters, you can associate the skip_empty_lines option with the trim option:

const parse = require('csv-parse/lib/sync')
const assert = require('assert')

const records = parse(`
"a","b","c"
\t
"d","e","f"
`, {
  skip_empty_lines: true,
  trim: true
})

assert.deepEqual(
  records, [
    ['a', 'b', 'c'],
    ['d', 'e', 'f']
  ]
)

Another possibility includes using a combination of skip_lines_with_empty_values and relax_column_count.