excellentexport 3.7.3 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/utils.d.ts CHANGED
@@ -17,6 +17,11 @@ export declare const getTable: (element: (HTMLTableElement | string)) => HTMLTab
17
17
  * @param {*} element
18
18
  */
19
19
  export declare const getAnchor: (element: (HTMLAnchorElement | string)) => HTMLAnchorElement;
20
+ /**
21
+ * Encode a value for CSV.
22
+ * @param {*} value
23
+ */
24
+ export declare const fixCSVField: (value: string, csvDelimiter: string) => string;
20
25
  export declare const tableToArray: (table: HTMLTableElement) => any[][];
21
26
  export declare const tableToCSV: (table: HTMLTableElement, csvDelimiter?: string, csvNewLine?: string) => string;
22
27
  export declare const createDownloadLink: (anchor: HTMLAnchorElement, base64data: string, exporttype: string, filename: string) => boolean;
package/index.rtl.html ADDED
@@ -0,0 +1,69 @@
1
+ <html>
2
+ <head>
3
+ <meta charset="utf-8">
4
+ <title>Export to excel test</title>
5
+ <script src="dist/excellentexport.js"></script>
6
+ <style>
7
+ table, tr, td {
8
+ border: 1px black solid;
9
+ }
10
+ </style>
11
+ <script>
12
+ function openFile(format) {
13
+ return ExcellentExport.convert({
14
+ anchor: 'anchorNewApi-' + format,
15
+ filename: 'data_123.' + format,
16
+ format: format,
17
+ rtl: true,
18
+ }, [{
19
+ name: 'Sheet Name Here 1',
20
+ from: {
21
+ table: 'datatable'
22
+ }
23
+ }]);
24
+ }
25
+ </script>
26
+ </head>
27
+ <body>
28
+ <h1>ExcellentExport.js RTL text</h1>
29
+
30
+ Check on <a href="http://jordiburgos.com">jordiburgos.com</a> and <a href="https://github.com/jmaister/excellentexport">GitHub</a>.
31
+
32
+ <h3>Test page</h3>
33
+
34
+ Test table
35
+ <table id="datatable">
36
+ <thead>
37
+ <tr>
38
+ <th>االلغة</th>
39
+ <th>عدد الأحرف</th>
40
+ <th>Country</th>
41
+ <th>miص-ص</th>
42
+ </tr>
43
+ </thead>
44
+ <tbody>
45
+ <tr>
46
+ <td>العربية</td>
47
+ <td>٢٨</td>
48
+ <td>Earth</td>
49
+ <td>ن0ن</td>
50
+ </tr>
51
+ <tr>
52
+ <td>العبرية</td>
53
+ <td>٢٢</td>
54
+ <td>Isreal</td>
55
+ <td>ضSض</td>
56
+ </tr>
57
+ </tbody>
58
+ </table>
59
+
60
+ <br/>
61
+
62
+ <a download="data_123.xls" href="#" id="anchorNewApi-xls" onclick="return openFile('xls');">Export to Excel: XLS format</a>
63
+ <br/>
64
+ <a download="data_123.xlsx" href="#" id="anchorNewApi-xlsx" onclick="return openFile('xlsx');">Export to Excel: XLSX format</a>
65
+ <br/>
66
+ <a download="data_123.csv" href="#" id="anchorNewApi-csv" onclick="return openFile('csv');">Export to CSV</a>
67
+
68
+ </body>
69
+ </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "excellentexport",
3
- "version": "3.7.3",
3
+ "version": "3.8.0",
4
4
  "description": "Client side JavaScript export to Excel or CSV",
5
5
  "license": "MIT",
6
6
  "homepage": "http://jordiburgos.com",
@@ -27,31 +27,34 @@
27
27
  },
28
28
  "main": "dist/excellentexport.js",
29
29
  "devDependencies": {
30
- "@babel/core": "7.15.8",
31
- "@babel/plugin-proposal-class-properties": "7.14.5",
32
- "@babel/plugin-transform-flow-strip-types": "7.14.5",
33
- "@babel/preset-env": "7.15.8",
34
- "@types/jest": "27.0.2",
35
- "@types/jest-environment-puppeteer": "4.4.1",
36
- "@types/node": "16.11.6",
30
+ "@babel/core": "7.16.12",
31
+ "@babel/plugin-proposal-class-properties": "7.16.7",
32
+ "@babel/plugin-transform-flow-strip-types": "7.16.7",
33
+ "@babel/preset-env": "7.16.11",
34
+ "@types/jest": "27.4.0",
35
+ "@types/jest-environment-puppeteer": "5.0.0",
36
+ "@types/node": "17.0.12",
37
37
  "@types/puppeteer": "5.4.4",
38
38
  "babel-loader": "8.2.3",
39
39
  "blob-polyfill": "6.0.20211015",
40
40
  "coveralls": "3.1.1",
41
41
  "cross-env": "7.0.3",
42
- "html-loader": "3.0.0",
43
- "jest": "27.3.1",
44
- "jest-puppeteer": "6.0.0",
45
- "puppeteer": "10.4.0",
46
- "ts-jest": "27.0.7",
42
+ "html-loader": "3.1.0",
43
+ "jest": "27.4.7",
44
+ "jest-puppeteer": "6.0.3",
45
+ "puppeteer": "13.1.2",
46
+ "ts-jest": "27.1.3",
47
47
  "ts-loader": "9.2.6",
48
- "ts-node": "10.3.0",
48
+ "ts-node": "10.4.0",
49
49
  "typescript": "4.3.4",
50
- "webdriverio": "7.16.3",
51
- "webpack": "5.60.0",
52
- "webpack-cli": "4.9.1",
53
- "webpack-dev-server": "4.3.1",
50
+ "webdriverio": "7.16.13",
51
+ "webpack": "5.67.0",
52
+ "webpack-cli": "4.9.2",
53
+ "webpack-dev-server": "4.7.3",
54
54
  "webpack-node-externals": "3.0.0",
55
- "xlsx": "0.17.3"
55
+ "xlsx": "0.17.5"
56
+ },
57
+ "resolutions": {
58
+ "json-schema": "0.4.0"
56
59
  }
57
60
  }
@@ -16,6 +16,7 @@ export interface ConvertOptions {
16
16
  openAsDownload?: boolean,
17
17
  format: ('csv' | 'xls' | 'xlsx'),
18
18
  filename?: string,
19
+ rtl?: boolean,
19
20
  }
20
21
  export interface FromOptions {
21
22
  table?: (string|HTMLTableElement),
@@ -28,13 +29,13 @@ export interface SheetOptions {
28
29
  filterRowFn?(row:any[]): boolean ,
29
30
  fixValue?(value:any, row:number, column:number): any,
30
31
  fixArray?(array:any[][]): any[][],
32
+ rtl?: boolean
31
33
  }
32
34
 
33
35
 
34
36
  const ExcellentExport = function() {
35
37
 
36
- const version = "3.7.3";
37
-
38
+ const version = "3.8.0";
38
39
 
39
40
  /*
40
41
  ExcellentExport.convert(options, sheets);
@@ -44,7 +45,8 @@ const ExcellentExport = function() {
44
45
  anchor: String or HTML Element,
45
46
  openAsDownload: boolean, // Use this options if not using an anchor tag
46
47
  format: 'xlsx' or 'xls' or 'csv',
47
- filename: String
48
+ filename: String,
49
+ rtl: boolean (optional), specify if all the workbook has text in RTL mode
48
50
  }
49
51
 
50
52
  Sheets must be an array of sheet configuration objects. Sheet description:
@@ -59,6 +61,7 @@ const ExcellentExport = function() {
59
61
  filterRowFn: function(row) {return true}, // Function to decide which rows are returned
60
62
  fixValue: function(value, row, column) {return fixedValue} // Function to fix values, receiving value, row num, column num
61
63
  fixArray: function(array) {return array} // Function to manipulate the whole data array
64
+ rtl: boolean // optional: specify if the sheet has text in RTL mode
62
65
  ...
63
66
  },
64
67
  {
@@ -69,7 +72,8 @@ const ExcellentExport = function() {
69
72
  const convert = function(options:ConvertOptions, sheets:SheetOptions[]) {
70
73
  const workbook = {
71
74
  SheetNames: [],
72
- Sheets: {}
75
+ Sheets: {},
76
+ Views: []
73
77
  };
74
78
 
75
79
  if (!options.format) {
@@ -86,7 +90,7 @@ const ExcellentExport = function() {
86
90
  }
87
91
 
88
92
  // Select data source
89
- let dataArray;
93
+ let dataArray: any[][];
90
94
  if (sheetConf.from && sheetConf.from.table) {
91
95
  dataArray = utils.tableToArray(utils.getTable(sheetConf.from.table));
92
96
  } else if(sheetConf.from && sheetConf.from.array) {
@@ -108,7 +112,7 @@ const ExcellentExport = function() {
108
112
  utils.removeColumns(dataArray, sheetConf.removeColumns);
109
113
  }
110
114
 
111
- // Convert data, by value
115
+ // Convert data. Function applied to each value independently, receiving (value, rownum, colnum)
112
116
  if (sheetConf.fixValue && typeof sheetConf.fixValue === 'function') {
113
117
  const fn = sheetConf.fixValue;
114
118
  dataArray.map((r, rownum) => {
@@ -128,6 +132,7 @@ const ExcellentExport = function() {
128
132
  workbook.SheetNames.push(name);
129
133
  const worksheet = XLSX.utils.aoa_to_sheet(dataArray, {sheet: name} as XLSX.AOA2SheetOpts);
130
134
  workbook.Sheets[name] = worksheet;
135
+ workbook.Views.push({RTL: options.rtl || sheetConf.rtl || false});
131
136
  });
132
137
 
133
138
  const wbOut:string = XLSX.write(workbook, {bookType: options.format, bookSST:true, type: 'binary'});
package/src/utils.ts CHANGED
@@ -37,7 +37,7 @@ export const base64 = function(s:string) : string {
37
37
 
38
38
  export const format = function(s:string, context:any) : string {
39
39
  return s.replace(new RegExp("{(\\w+)}", "g"), function(m, p) {
40
- return context[p];
40
+ return context[p] || "{" + p + "}";
41
41
  });
42
42
  };
43
43
 
@@ -67,7 +67,7 @@ export const getAnchor = function(element :(HTMLAnchorElement|string)) : HTMLAnc
67
67
  * Encode a value for CSV.
68
68
  * @param {*} value
69
69
  */
70
- const fixCSVField = function(value:string, csvDelimiter:string) {
70
+ export const fixCSVField = function(value:string, csvDelimiter:string) : string {
71
71
  let fixedValue = value;
72
72
  const addQuotes = (value.indexOf(csvDelimiter) !== -1) || (value.indexOf('\r') !== -1) || (value.indexOf('\n') !== -1);
73
73
  const replaceDoubleQuotes = (value.indexOf('"') !== -1);
@@ -0,0 +1,29 @@
1
+ const assert = require('assert');
2
+
3
+ import * as utils from '../src/utils';
4
+
5
+
6
+ describe('Test utility functions', () => {
7
+
8
+ describe('base64', () => {
9
+ it('should encode a string to base64', () => {
10
+ assert.equal(utils.base64('test'), 'dGVzdA==');
11
+ });
12
+
13
+ it('should encode a unicode string to base64', () => {
14
+ assert.equal(utils.base64('test\u00A9'), "dGVzdMKp");
15
+ });
16
+
17
+ });
18
+
19
+
20
+ describe('test format function', () => {
21
+ it('should format a string', () => {
22
+ assert.equal(utils.format('aaaa {a} bbbb {b} cccc', {a:'1', b:'2', c:'3', d:'4'}), 'aaaa 1 bbbb 2 cccc');
23
+ });
24
+
25
+ it('should not replace if no data is provided', () => {
26
+ assert.equal(utils.format('aaaa {a} bbbb {b} cccc', {}), 'aaaa {a} bbbb {b} cccc');
27
+ });
28
+ });
29
+ });
@@ -0,0 +1,24 @@
1
+ const assert = require('assert');
2
+
3
+ import { fixCSVField } from '../src/utils';
4
+
5
+
6
+ describe('Test utility functions: csv functions', () => {
7
+
8
+ it('should keep the value if not delimiter found', () => {
9
+ assert.equal(fixCSVField('test', ','), 'test');
10
+ });
11
+
12
+ it('should fix a string with double quotes', () => {
13
+ const str = 'aaa"bbb';
14
+ const result = fixCSVField(str, "\"");
15
+ assert.equal(result, '\"aaa\"\"bbb\"');
16
+ });
17
+
18
+ it('should fix a field with space delimiter', () => {
19
+ const str = 'aaa bbb';
20
+ const result = fixCSVField(str, " ");
21
+ assert.equal(result, '\"aaa bbb\"');
22
+ });
23
+
24
+ });
@@ -3,9 +3,7 @@ const assert = require('assert');
3
3
  import { removeColumns } from '../src/utils';
4
4
 
5
5
 
6
- describe('Test utility functions', () => {
7
- beforeEach(() => {
8
- });
6
+ describe('Test utility functions: removeColumns', () => {
9
7
 
10
8
  it('should remove one column correctly', function() {
11
9
  const columns = [
package/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "14"
4
- env:
5
- - MOZ_HEADLESS=1
6
- addons:
7
- firefox: latest
8
- cache:
9
- yarn: true