csv

Rudimentary CSV encoder and decoder

Import

_ <- fat.extra.csv

Variables

These entries are defined via import and can be updated afterwards to configure library methods behavior:

  • csvSeparator, default is comma ','
  • csvReplacement, default is empty text ''

Methods

Name Signature Brief
toCsv (header: List/Text, rows: List/Scope): Text Build csv from rows
fromCsv (csv: Text): List/Scope Parse csv into list of rows

types package is automatically imported with this import

Usage

toCsv

Sample code:

_ <- fat.extra.csv

headers = [ 'name', 'stock', 'sale' ]

data = [
  { sale = true,  stock = 52, name = 'Apple' }
  { sale = false, stock = 35, name = 'Orange' }
  { sale = true,  stock = 24, name = 'Banana' }
]

toCsv(headers, data)  # name,stock,sale\nApple,52,true\nOrange,35,false...

csvReplacement is used by toCsv as replacement in case a csvSeparator is found within a text being encoded

fromCsv

Sample code:

csvData = fromCsv(data)  # original data List/Scope

escaping input containing csvSeparator with quotes is not supported

See also

results matching ""

    No results matching ""