CSVParse for Node.js

IssuesGitHub

Option quote

The quote option defines the characters used to surround a field.

The presence of quotes around the field is optional and is automatically detected. The value can be one or multiple characters. The detection of quotes is disabled with the null, false and empty string values. it defaults to " (double quote).

Default behavior

The quote option default to ". Fields do not need to be quoted as illustrated in this example:

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

const records = parse(`
a,"b",c
"d",e,"f"
`.trim());

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

Quotes inside the field

Quote characters present inside a field must be escaped. The default escape character is ".

This example contains quotes inside the second field:

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

const records = parse(`
a,"b""b",c
d,"e""e",f
`.trim());

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

About

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