Metreeca MIME
    Preparing search index...

    Function csv

    • Creates a CSV parser.

      The task converts a feed of CSV documents into a feed of records, one Record per data row, so that downstream tasks work on structured data rather than on text.

      Each document is given either as text or as a response carrying it in its body. A response without a body produces no records.

      Response bodies are decoded with the charset parameter of their content type. If no charset is stated, bodies are decoded as UTF-8 rather than as the US-ASCII default of text media types, since UTF-8 is the encoding CSV sources use in practice. A leading byte order mark is stripped, both from text and from bodies in a Unicode charset.

      Sources often serve CSV as text/plain or under vendor types. A response with a content type other than text/csv or application/csv is therefore logged as a warning and parsed anyway. A response with a charset the platform can't decode is also logged, and its body is decoded as UTF-8.

      Note

      • Incremental: each record is emitted as soon as it is parsed, so endless sources are processed for as long as the feed is consumed.
      • Streaming: documents are drawn one at a time and response bodies are read as records are requested, so resources of any size are processed without being held in memory, and a consumer that stops early releases the source. Documents given as text are parsed in one go, and part of a body may be read ahead of the records actually consumed.
      • Stateless: each document is parsed independently, including its own header row, so the result doesn't depend on how the feed is split across nested feeds or runs.
      Warning

      Malformed records are skipped and logged as warnings, and the feed runs to completion.

      Type Parameters

      • R extends Record = Record

        The type of the records produced; field values are emitted as parsed and are not validated against it

      Parameters

      • options: {
            header?: boolean;
            skip?: boolean;
            trim?: boolean;
            flex?: boolean;
            quote?: string;
            delimiter?: string;
        } = {}

        The parsing options

        • Optional Readonlyheader?: boolean

          Reads the first row of each document as column labels, keying records by label rather than by positional index; defaults to false

        • Optional Readonlyskip?: boolean

          Skips lines without content, either empty or containing delimiters only; a row with at least one non-blank field is kept; defaults to false

        • Optional Readonlytrim?: boolean

          Strips surrounding whitespace from field values and column labels, quoted values included; a field left blank after trimming is undefined rather than an empty string; defaults to false

        • Optional Readonlyflex?: boolean

          Emits records whose field count doesn't match the header rather than skipping them; missing fields are left out and fields beyond the header are discarded; defaults to false

        • Optional Readonlyquote?: string

          The character wrapping field values; defaults to " if unset or empty

        • Optional Readonlydelimiter?: string

          The character separating fields; defaults to , if unset or empty

      Returns Task<string | Response, R>

      A task converting a feed of CSV documents, given as text or as responses, into a feed of records

      Error While the feed is consumed, if the source feed fails or a response body can't be read