CSVParse for Node.js

IssuesGitHub

Option skip_empty_lines

The skip_empty_lines skips any line which is empty.

Example

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

import assert from 'node:assert';
import { parse } from 'csv-parse/sync';

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

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

assert.deepStrictEqual(
  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:

import assert from 'node:assert';
import { parse } from 'csv-parse/sync';

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

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

Another possibility includes using a combination of skip_records_with_empty_values and relax_column_count.

About

The Node.js CSV project is an open source product hosted on GitHub and developed by Adaltas.