samthor / tiddlycsv

small, streaming CSV parser (~1kb)
Apache License 2.0
7 stars 0 forks source link

tiddlycsv is a small, streaming CSV parser. It's about ~1.3kb, has zero dependencies, and is tree-shakable.

Doesn't care about headers, keyed rows, anything but strings. Just supports the CSV spec including multi-line and quoted strings. Supports \r\n as well as \n for line separators only (i.e., won't rewrite \r\n to \n within multi-line strings).

Usage

Install tiddlycsv. Includes types.

Methods

In general, if the read helpers don't work for you, use buildCSVChunkStreamer and provide data your way. Minifying that method only is about ~0.55k.

Speed

It's fast for its size. To parse multiple copies of 1.csv:

tiddlycsv: 837.074ms (baseline) ~1.3kb
udsv: 540.037ms (0.63x) ~5kb
but-csv: 737.836ms (0.88x) ~0.5kb
papaparse: 1.120s (1.34x) ~20kb

Output

Unlike other parsers, tiddlycsv will return empty strings for trailing commas and empty lines. It skips the last input line if it does not have any data. For the input data:

Name,Age
Sam,37
Jim,

Anne,56

You'll get results like:

[["Name", "Age"], ["Sam", "37"], ["Jim", ""], [""], ["Anne", "56"]]

Should this be configurable? Maybe!