CSVStringify for Node.js

IssuesGitHub

Option escape_formulas

Escape values that start with =, +, -, @, \t, or \r with ' and defend against CSV injection attacks.

Example

In the escape formulas example, every field wich starts with the values = and @ is escaped by prefixing its value with '.

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

const records = stringify([
  ['=1', '@2', '3'],
  ['=4', '@5', '6']
], {escape_formulas: true});

assert.equal(records, "'=1,'@2,3\n'=4,'@5,6\n");

About

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