Skip to content
velt/encoding/csv exports

velt/encoding/csv

API reference

RFC 4180 CSV. Quoted fields may contain delimiters, "" escapes and line breaks. For a walkthrough, read the guide.

import { parseCsv, parseCsvRecords, stringifyCsv } from "velt/encoding/csv";

Exports

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.

function

parseCsvRecords

#std/encoding/csv/parse.vlt:170

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 = {}): string

Writes 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 Error

A 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 yet
constructor(message: string, line: i64)No doc comment yet

Re-exported from velt/encoding/csv/parse

Options for parseCsv / parseCsvRecords.

FieldTypeDescription
delimiter? stringOne ASCII character (default ,; e.g. ; or \t).
trim? boolStrip spaces and tabs around every field, quoted or not (default false).
skipEmptyLines? boolDrop records that are one empty field, i.e. blank lines (default false).

Re-exported from velt/encoding/csv/stringify

Options for stringifyCsv.

FieldTypeDescription
delimiter? stringOne ASCII character (default ,).
crlf? boolEnd records with \r\n as RFC 4180 says (default false: \n).