Module

Node.Stream.CSV.Parse

Package
purescript-csv-stream
Repository
cakekindel/purescript-csv-stream

#CSVRead Source

data CSVRead

#CSVParser Source

type CSVParser :: Row Type -> Row Type -> Typetype CSVParser a r = Stream (csv :: CSVRead, read :: Read, write :: Write | r)

Stream transforming chunks of a CSV file into parsed purescript objects.

The CSV contents may be piped into this stream as Buffer or String encoded chunks.

Records can be read with read when Node.Stream.readable is true.

#Config Source

type Config :: Row Type -> Row Typetype Config r = (bom :: Boolean, comment :: String, comment_no_infix :: Boolean, delimiter :: String, encoding :: String, escape :: String, from :: Int, from_line :: Int, group_columns_by_name :: Boolean, ignore_last_delimiters :: Boolean, info :: Boolean, ltrim :: Boolean, max_record_size :: Int, quote :: String, raw :: Boolean, record_delimiter :: String, relax_column_count :: Boolean, rtrim :: Boolean, skip_empty_lines :: Boolean, skip_records_with_empty_values :: Boolean, skip_records_with_error :: Boolean, to :: Int, to_line :: Int, trim :: Boolean | r)

https://csv.js.org/parse/options/

#make Source

make :: forall @r rl @config @missing @extra. RowToList r rl => ReadCSVRecord r rl => Union config missing (Config extra) => Record config -> Effect (CSVParser r ())

Create a CSVParser

#parse Source

parse :: forall @r rl @config missing extra. RowToList r rl => ReadCSVRecord r rl => Union config missing (Config extra) => Record config -> String -> Aff (Array (Record r))

Synchronously parse a CSV string

#foreach Source

foreach :: forall @r rl x. RowToList r rl => ReadCSVRecord r rl => CSVParser r x -> (Record r -> Aff Unit) -> Aff Unit

Loop until the stream is closed, invoking the callback with each record as it is parsed.

#read Source

read :: forall @r rl a. RowToList r rl => ReadCSVRecord r rl => CSVParser r a -> Effect (Maybe (Record r))

Reads a parsed record from the stream.

Returns Nothing when either:

  • The internal buffer of parsed records has been exhausted, but there will be more (Node.Stream.readable and Node.Stream.closed are both false)
  • All records have been processed (Node.Stream.closed is true)

#readAll Source

readAll :: forall @r rl a. RowToList r rl => ReadCSVRecord r rl => CSVParser r a -> Aff (Array (Record r))

Collect all parsed records into an array

#dataH Source

dataH :: forall r a. EventHandle1 (CSVParser r a) (Record r)

data event. Emitted when a CSV record has been parsed.

#makeImpl Source

makeImpl :: forall r. Foreign -> Effect (Stream r)

FFI

#readImpl Source

readImpl :: forall r. Stream r -> Effect (Nullable (Array String))

FFI

#columnsArrayImpl Source

columnsArrayImpl :: forall r. Stream r -> Effect (Array String)

FFI

#columnsMapImpl Source

columnsMapImpl :: forall r. Stream r -> Effect (Nullable (Map String Int))

FFI

#setColumnsMapImpl Source

setColumnsMapImpl :: forall r. Stream r -> Map String Int -> Effect Unit

FFI

#getOrInitColumnsMap Source

getOrInitColumnsMap :: forall r x. CSVParser r x -> Effect (Maybe (Map String Int))

FFI

#recordToForeign Source

recordToForeign :: forall r. Record r -> Object Foreign

FFI