@@ -8,10 +8,17 @@ The main purpose of this library is to provide an easy way to export your data a
88
99## Installation
1010
11+ ### npm
12+
13+ ``` bash
14+ $ npm i @lcluber/csvxjs
15+ ```
16+
17+ ### yarn
18+
1119``` bash
12- $ npm install @lcluber/csvxjs
20+ $ yarn add @lcluber/csvxjs
1321```
14- Or download it ** [ here] ( http://csvxjs.lcluber.com/#download ) ** .
1522
1623## Usage
1724
@@ -29,27 +36,34 @@ import { Export, Convert } from '@lcluber/csvxjs';
2936let array = [
3037 {
3138 firstname: ' Galileo' ,
32- lastname: ' Galilei ' ,
39+ lastname: ' Galiléi ' ,
3340 born: 1564 ,
3441 died: 1642
3542 },
3643 {
3744 firstname: ' Nikola' ,
3845 lastname: ' Tesla' ,
46+ city: ' Smiljan' ,
3947 born: 1856 ,
4048 died: 1943
4149 },
4250 {
4351 firstname: ' Albert' ,
44- lastname: ' Einstein' ,
4552 born: 1879 ,
53+ lastname: ' Einstein' ,
4654 died: 1955
4755 }
4856];
49-
57+ let customLabels = {
58+ firstname: ' First name' ,
59+ lastname: ' Last name' ,
60+ city: ' City' ,
61+ born: ' Born' ,
62+ died: ' Died'
63+ };
5064let exportButton = document .getElementById (' csv' );
5165exportButton .addEventListener (' click' , function () {
52- Export .data (' scientists' ,array,{separator: ' ;' });// ; separator for excel friendly imports
66+ Export .data (' scientists' ,array,{separator: ' ;' , customLabels : customLabels });// ; separator for excel friendly imports
5367});
5468
5569// Convert CSV data to HTML table
@@ -73,29 +87,36 @@ document.getElementById("table").innerHTML = Convert.table(data,{separator: ';'}
7387
7488// Convert an array to CSV file
7589var array = [
76- {
90+ {
7791 firstname: ' Galileo' ,
78- lastname: ' Galilei ' ,
92+ lastname: ' Galiléi ' ,
7993 born: 1564 ,
8094 died: 1642
8195 },
8296 {
8397 firstname: ' Nikola' ,
8498 lastname: ' Tesla' ,
99+ city: ' Smiljan' ,
85100 born: 1856 ,
86101 died: 1943
87102 },
88103 {
89104 firstname: ' Albert' ,
90- lastname: ' Einstein' ,
91105 born: 1879 ,
106+ lastname: ' Einstein' ,
92107 died: 1955
93108 }
94109];
95-
110+ var customLabels = {
111+ firstname: ' First name' ,
112+ lastname: ' Last name' ,
113+ city: ' City' ,
114+ born: ' Born' ,
115+ died: ' Died'
116+ };
96117var exportButton = document .getElementById (' csv' );
97118exportButton .addEventListener (' click' , function () {
98- CSVx .Export .data (' scientists' ,array,{separator: ' ;' });// ; separator for excel friendly imports
119+ CSVx .Export .data (' scientists' ,array,{separator: ' ;' , customLabels : customLabels });// ; separator for excel friendly imports
99120});
100121
101122// Convert CSV data to HTML table
@@ -110,14 +131,16 @@ document.getElementById("table").innerHTML = CSVx.Convert.table(data,{separator:
110131### Options
111132
112133``` javascript
134+ interface Data { [key: string]: number| string }[]
135+
113136interface Options {
114137 data?: string; // default : 'text/csv'
115138 charset?: string; // default : 'utf-8'
116139 labels?: boolean; // default : true
117140 quote?: string; // default : '"'
118141 separator?: string; // default : ','
119142 CRLF ?: string; // default : '\r\n'
120- customLabels?: string[] ; // default : []
143+ customLabels: { [key : string] : string } ; // default : {}
121144}
122145
123146interface CSS {
@@ -126,18 +149,6 @@ interface CSS {
126149}
127150```
128151
129- ## Demo
130-
131- See a basic example ** [ here] ( http://csvxjs.lcluber.com/#example ) ** .
132-
133- ## API Reference
134-
135- Read the documentation ** [ here] ( http://csvxjs.lcluber.com/doc/ ) ** .
136-
137- ## Tests
138-
139- No tests to run yet
140-
141152## Contributors
142153
143154CSVx.js is still in early development and I would be glad to get all the help you can provide for this project.
0 commit comments