velt/encoding/csv
API referenceRFC 4180 CSV. Quoted fields may contain delimiters, "" escapes and line breaks. For a walkthrough, read the guide.
Exports
line is the 1-based line where the problem starts (0 for option errors).CsvOptionsOptions for parseCsv / parseCsvRecords.CsvWriteOptionsOptions for stringifyCsv.Re-exported from velt/encoding/csv/parse
function parseCsv(text: string, opts: CsvOptions = {}): string[][]Parses CSV text into records of fields. Throws CsvError on an unterminated quoted field,
text after a closing quote, or an invalid delimiter.
Re-exported from velt/encoding/csv/parse
function parseCsvRecords(
text: string,
opts: CsvOptions = {},
): Map<string, string>[]Parses CSV whose first record is a header: one map per following record, keyed by header names in header order. Missing trailing fields are "", extra fields are ignored, and a repeated header name keeps its last value.
Re-exported from velt/encoding/csv/stringify
function stringifyCsv(rows: string[][], opts: CsvWriteOptions = {}): stringWrites records as CSV, quoting only fields that need it; every record ends with a line break.
Throws CsvError on an invalid delimiter.
Re-exported from velt/encoding/csv/errors
class CsvError extends ErrorA malformed CSV input or a bad option; line is the 1-based line where the problem starts
(0 for option errors).
line: i64No doc comment yetconstructor(message: string, line: i64)No doc comment yetRe-exported from velt/encoding/csv/parse
Options for parseCsv / parseCsvRecords.
Parameter ofparseCsvparseCsvRecords
| Field | Type | Description |
|---|---|---|
| delimiter? | string | One ASCII character (default ,; e.g. ; or \t). |
| trim? | bool | Strip spaces and tabs around every field, quoted or not (default false). |
| skipEmptyLines? | bool | Drop records that are one empty field, i.e. blank lines (default false). |
Re-exported from velt/encoding/csv/stringify
Options for stringifyCsv.
Parameter ofstringifyCsv
| Field | Type | Description |
|---|---|---|
| delimiter? | string | One ASCII character (default ,). |
| crlf? | bool | End records with \r\n as RFC 4180 says (default false: \n). |