stdcsv2 - anssihalmeaho/funl GitHub Wiki

stdcsv2

Implements extended services to convert CSV to/from list of maps. In these maps field names are keys of each map and values of line are map values.

Functions

lines-to-maps

Converts from lines to maps. Keys of maps are taken from header list.

type: function

Format:

call(stdcsv2.lines-to-maps list:lines) -> list: maps

csv-to-maps

Converts bytearray given as argument to list of maps.

Optionally options map can be given as 2nd argument (see stdcsv for options map contents).

type: function

Format:

call(stdcsv2.csv-to-maps opaque:bytearray) -> list(is-ok error-description list:maps)

call(stdcsv2.csv-to-maps opaque:bytearray options:map) -> list(is-ok error-description list:maps)

Return value: list

Returned list contains

  1. bool: true if succeeded, false otherwise
  2. error description (string), '' if succeeded
  3. list of maps

maps-to-lines

Converts list of maps (given as 2nd argument) to list of lines. Order of fields is determined from given header list (1st argument).

type: function

Format:

call(stdcsv2.maps-to-lines header maps) -> list of lines

Return value: list

maps-to-csv

Converts given list of maps (given as 2nd argument) to CSV formatted bytearray. Order of fields is determined from given header list (1st argument).

Optionally options map can be given as 3rd argument (see stdcsv for options map contents).

type: function

Format:

call(stdcsv2.maps-to-csv header maps) -> list(is-ok error-description opaque:bytearray)

call(stdcsv2.maps-to-csv header maps options:map) -> list(is-ok error-description opaque:bytearray)

Return value: list

Returned list contains

  1. bool: true if succeeded, false otherwise
  2. error description (string), '' if succeeded
  3. bytearray in CSV format