// Parse from a stream (useful for large files) constsource = ReadableStream.from([ "name,age,city\n", "john,30,new york\n", "mary,25,los angeles\n" ]);
// When using an array of objects, you must specify columns to use constcustomColumns = stringify(objectData, { columns: ["city", "name", "age"] }); assertEquals(customColumns, "city,name,age\r\nnew york,john,30\r\nlos angeles,mary,25\r\n");
There are many kinds of CSV files; this module supports the format described
in RFC 4180.
A csv file contains zero or more records of one or more fields per record.
Each record is separated by the newline character. The final record may
optionally be followed by a newline character.
field1,field2,field3
White space is considered part of a field.
Carriage returns before newline characters are silently removed.
Blank lines are ignored. A line with only whitespace characters (excluding
the ending newline character) is not considered a blank line.
Fields which start and stop with the quote character " are called
quoted-fields. The beginning and ending quote are not part of the field.
The source:
normal string,"quoted-field"
results in the fields
[`normal string`, `quoted-field`]
Within a quoted-field a quote character followed by a second quote character is considered a single quote.
"the ""word"" is true","a ""quoted-field"""
results in
[`the "word" is true`, `a "quoted-field"`]
Newlines and commas may be included in a quoted-field
Reads and writes comma-separated values (CSV) files.
Parsing CSV
Parsing CSV from a Stream
Stringifying Data to CSV
Streaming Stringify Data to CSV
CSV Format Information
There are many kinds of CSV files; this module supports the format described in RFC 4180.
A csv file contains zero or more records of one or more fields per record. Each record is separated by the newline character. The final record may optionally be followed by a newline character.
White space is considered part of a field.
Carriage returns before newline characters are silently removed.
Blank lines are ignored. A line with only whitespace characters (excluding the ending newline character) is not considered a blank line.
Fields which start and stop with the quote character " are called quoted-fields. The beginning and ending quote are not part of the field.
The source:
results in the fields
Within a quoted-field a quote character followed by a second quote character is considered a single quote.
results in
Newlines and commas may be included in a quoted-field
results in