CSVStringify for Node.js

IssuesGitHub

Option escape

Single character used for escaping. It only applies to characters matching the quote and the escape options default to double quotes (").

  • Type: string|Buffer
  • Optional
  • Default: false
  • Since: 0.0.1

Default behavior

The default escape value is double quotes ("). It is automatically applied when quotes are present.

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

const records = stringify([
  ['a "value"'],
]);

assert.equal(records, '"a ""value"""\n');

Using a custom value

The custom escape example, uses the alternative backslash (\).

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

const records = stringify([
  ['a "value"'],
], {escape: '\\'});

assert.equal(records, '"a \\"value\\""\n');

About

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