Skip to content

Migration

Moving to csv-pipe is usually a one-line change per call plus a small option remap. It quotes per RFC 4180 by default and infers the header from the record keys, so many call sites need nothing more. This page covers encoding; parsing maps the same way (Papa.parse, csv-parse, and parseStream to parse and createCsvParser), with the parsing options as the target.

Option names below reflect the documented behavior of each library and may change between versions; check the current docs of each.

From papaparse

Papa.unparse returns a string, and so does stringify.

ts
// Before
import Papa from 'papaparse';
Papa.unparse(rows);

// After
import { stringify } from 'csv-pipe';
stringify(rows);
papaparse (unparse config)csv-pipe
delimiterseparator
newlinenewline
header: falseshowHeaders: false
columns: ['a', 'b']columns: ['a', 'b']
quoteCharquote
quotes: truequoting: 'all'
escapeCharnot configurable; quotes are doubled per RFC 4180

From csv-stringify

Use the synchronous entry to match stringify's signature.

ts
// Before
import { stringify } from 'csv-stringify/sync';
stringify(rows, { header: true });

// After
import { stringify } from 'csv-pipe';
stringify(rows);
csv-stringify optioncsv-pipe
delimiterseparator
record_delimiternewline
header: falseshowHeaders: false
columns: ['a', 'b'] or { a: 'A' }columns: ['a', 'b'] or { a: 'A' }
quotequote
quoted: truequoting: 'all'
bom: truebom: true
cast: { ... }format hook

From fast-csv

writeToString is asynchronous; stringify is synchronous, so you can drop the await.

ts
// Before
import { writeToString } from '@fast-csv/format';
const csv = await writeToString(rows, { headers: true });

// After
import { stringify } from 'csv-pipe';
const csv = stringify(rows);
fast-csv optioncsv-pipe
delimiterseparator
rowDelimiternewline
headers: falseshowHeaders: false
headers: ['a', 'b']columns: ['a', 'b']
quotequote
quoteColumns: truequoting: 'all'
writeBOM: truebom: true
transformformat hook

For streaming, swap the fast-csv format() transform for createCsvEncoder(...).stream(...), and wrap it with toReadableStream for a Web response or Readable.from for a Node stream.

Behavior to know after switching

  • Quoting is minimal by default. A field is quoted only when it contains the separator, a quote, or a line break. Use quoting: 'all' to quote everything.
  • Quotes are escaped by doubling, per RFC 4180. There is no separate escape character.
  • The header is inferred from the record keys unless you pass columns or showHeaders: false.
  • Date renders as an ISO 8601 string, and null, undefined, and NaN render as an empty string. Adjust with format and the text options.
  • Columns are typed. A key that is not on your record is a compile error. See TypeScript.

Released under the MIT License.