JS Array To CSV Exporter And CSV To Table Converter – CSVx.js

Category: Javascript | December 12, 2020
Author:LCluber
Views Total:481 views
Official Page:Go to website
Last Update:December 12, 2020
License:MIT

Preview:

JS Array To CSV Exporter And CSV To Table Converter – CSVx.js

Description:

CSVx.js is a small and easy-to-use JavaScript library that generates a downloadable CSV file from a JavaScript array and populates an HTML table with the CSV data.

How to use it:

Install & Download.

# NPM
$ npm install @lcluber/csvxjs --save

Import the Export and Convert modules.

import { Export, Convert } from '@lcluber/csvxjs';

Conver an array of objects into a CSV file. Possible parameters:

  • filename: custom file name
  • data: data array
  • options: options
var array = [
    {
      firstname:'Jill',
      lastname:'Smith',
      age:50
    },
    {
      firstname:'Eve',
      lastname:'Jacksona',
      age:94
    },
    {
      firstname:'Mary',
      lastname:'Moe',
      age:43
    }
];
Export.data('example',array,{
  separator: ';'
});

Convert CSV data into an HTML table. Possible parameters:

  • data: CSV data
  • options: options
  • css: additional CSS classes
var data = '"Firstname";"Lastname";"Age"\r\n\
"Jill";"Smith";"50"\r\n\
"Eve";"Jacksona";"94"\r\n\
"Mary";"Moe";"43"';
document.getElementById("table").innerHTML = Convert.table(data,{separator: ';'}, {table: 'table'});

Possible options for the Export.

Export.data('example',array,{
  data: 'text/csv',
  charset: 'utf-8',
  labels: true,
  quote: '"',
  separator: ',',
  CRLF: '\r\n',
  customLabels: []
});

Possible options for the Convert.

Convert.table(data,{
  labels: true,
  quote: '"',
  separator: ',',
  CRLF: '\r\n'
},{
  table: '',
  th: ''
});

Changelog:

v0.2.1 (12/12/2020)

  • Fix declaration file
  • Lighter library
  • Delete Mouette.js and Wee.js devDependencies

v0.2.0 (11/17/2020)

  • Added support for array of different objects

v0.1.11 (04/10/2020)

  • fix custom labels issue on firefox

v0.1.10 (04/11/2019)

  • Fixed csv export with better filename checking

v0.1.9 (04/10/2019)

  • Fixed csv export with special characters

v0.1.8 (04/01/2019)

  • Improved typings

You Might Be Interested In:


2 thoughts on “JS Array To CSV Exporter And CSV To Table Converter – CSVx.js

Leave a Reply