CSVParse for Node.js

IssuesGitHub

Option record_delimiter

The record_delimiter option defines one or multiple characters used to delimit records.

The value may be a string or a buffer or an array of both. It can not be empty. By defaults, the record delimiters are auto discovered. Supported auto discovery methods are Linux ("\n"), Apple ("\r") and Windows ("\r\n") record delimiters.

It is not possible to escape a record delimiter. A field must be quoted if it contains a record delimiter which should not be interpreted as such.

History

Before version 4.0.0, this option was named rowDelimiter.

Single value record delimiter

In the record delimiter example, two characters && separate records.

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

const data = 'a,b,c&&d,e,f';
const records = parse(data, {
  record_delimiter: '&&'
});
assert.deepStrictEqual(records, [
  [ 'a', 'b', 'c' ],
  [ 'd', 'e', 'f' ]
]);

Array of record delimiter values

Record delimiter can be made of multiple values when defined as an array:

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

const data = 'a,b,c&&d,e,f||h,i,j';
const records = parse(data, {
  record_delimiter: ['&&', '||']
});
assert.deepStrictEqual(records, [
  [ 'a', 'b', 'c' ],
  [ 'd', 'e', 'f' ],
  [ 'h', 'i', 'j' ]
]);