Fliplet.CSV

Install

Add the fliplet-csv dependency to your screen or app resources.

Fliplet.CSV.encode()

(Returns String)

Encodes JSON data into CSV.

Fliplet.CSV.encode(data, options);
  • data (Object Array) JSON data to be encoded into CSV.
  • options (Object) Optional configuration for further CSV encoding. See Papa Parse documentation for more. Note Fliplet CSV uses \n as the newline sequence by default to maximize CSV sharbility and support across all platforms. In addition, the following options are also supported:
    • base64 (Boolean) Set as true to encode the CSV data in Base64 encoding. (Default: false)
    • dataUrl (Boolean) Set as true to encode the CSV data as data: URL. (Default: false)

The CSV JS API uses Papa Parse as the underlying engine. This means it’s capable of generating CSV with different data formats. Examples:

// Specifying a collection of entries
Fliplet.CSV.encode([
  { 'Column 1', 'foo', 'Column 2': 'bar' },
  { 'Column 1', 'abc', 'Column 2': 'def' }
]);

// Pick specific columns from a collection of entries
Fliplet.CSV.encode([
  { 'Column 1', 'foo', 'Column 2': 'bar', 'Column 3': 'baz' },
  { 'Column 1', 'abc', 'Column 2': 'def', 'Column 3': 'ghi' }
], {
  columns: ['Column 3', 'Column 1'] // Show only the specified columns, in given order
});

// Specifying fields and data explicitly
Fliplet.CSV.encode({
  fields: ['Column 1', 'Column 2'],
  data: [
    ['foo', 'bar'],
    ['abc', 'def']
  ]
});

// Two-line, comma-delimited, without header row
Fliplet.CSV.encode([
  ['1-1', '1-2', '1-3'],
  ['2-1', '2-2', '2-3']
]);

Fliplet.CSV.decode()

(Returns Array)

Decodes CSV string into JSON data.

Fliplet.CSV.decode(csv, options);
  • csv (String) CSV string to be decoded.
  • options Optional configuration for further CSV encoding. See Papa Parse documentation for more.

Fliplet.CSV.download()

(Returns Promise)

Downloads JSON data as a CSV file.

Note Downloading CSV files only works in web apps.

Fliplet.CSV.download(data, options);
  • data JSON data to be encoded into CSV.
  • options (Object) Optional configuration for further CSV encoding. See Fliplet.CSV.encode() above for more information. In addition, the following options are also supported:
    • fileName (String) Full file name (including file extension) for the downloaded file. (Default: Untitled.csv)

Fliplet.CSV.email()

Attachs CSV file to an email.

(Returns Promise)

Emails JSON data as a CSV attachment.

Note Attaching CSV files to emails only works in native apps.

Fliplet.CSV.email(data, options);
  • data JSON data to be encoded into CSV.
  • options (Object) Optional configuration for further CSV encoding. See Fliplet.CSV.encode() above for more information. In addition, the following options are also supported:

Back to API documentation