CSVParse for Node.js

IssuesGitHub

Option escape

Table of Contents

The escape option set the escape character as one character/byte only. It only applies to quote and escape characters inside quoted fields.

The default value is " (double quote) when no option is provided and when the value is undefined or true. The values null and false disable escaping.

  • Type: Buffer|string|null|boolean
  • Optional
  • Default: "
  • Since: 0.0.1

Default behavior

The default example doesn't need to declare the escape option. It is activated by default with the " character. Note how it only apply inside a quoted field.

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

const data = `a,"b""c",d`;
const records = parse(data);
assert.deepStrictEqual(records, [
  [ 'a', 'b"c', 'd' ]
]);

Custom behavior

The custom example change the default behavior by setting the escape character to \ (backslash).

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

const data = `a,"b\\"c",d`;
const records = parse(data, { escape: '\\' });
assert.deepStrictEqual(records, [
  [ 'a', 'b"c', 'd' ]
]);

About

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