excellentexport 3.9.11 → 3.9.15

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.
@@ -1,129 +1,130 @@
1
- const assert = require('assert');
2
-
3
- import ExcellentExport, { ConvertOptions, SheetOptions } from '../src/excellentexport';
4
-
5
-
6
- describe('convert() API', function() {
7
- describe('Negative tests', function() {
8
-
9
- beforeEach(() => {
10
- window.URL.createObjectURL = () => "blob:fake_URL";
11
-
12
- const element = document.createElement("div");
13
- element.innerHTML = '<a id="anchor">Link</a>';
14
-
15
- document.body.appendChild(element);
16
- });
17
-
18
- it('should fail if CSV has more than one sheet', function() {
19
- const options = {
20
- anchor: 'anchor',
21
- filename: 'data_from_array',
22
- format: 'csv'
23
- } as ConvertOptions;
24
-
25
- const sheets = [{
26
- name: 'Sheet Name Here 1',
27
- from: {}
28
- }, {
29
- name: 'Sheet Number 2',
30
- from: {}
31
- }];
32
-
33
- assert.throws(() => {
34
- ExcellentExport.convert(options, sheets)
35
- }, Error);
36
-
37
- });
38
-
39
- it('should fail if sheet does not have name', function() {
40
- const options = {
41
- anchor: 'anchor',
42
- filename: 'data_from_array',
43
- format: 'csv'
44
- } as ConvertOptions;
45
-
46
- const sheets = [{
47
- // name: 'Sheet Name Here 1',
48
- from: {}
49
- }] as SheetOptions[];
50
-
51
- assert.throws(() => {
52
- ExcellentExport.convert(options, sheets)
53
- }, Error);
54
-
55
- });
56
-
57
- it('should fail if sheet does not have data', function() {
58
- const options = {
59
- anchor: 'anchor',
60
- filename: 'data_from_array',
61
- format: 'csv'
62
- } as ConvertOptions;
63
-
64
- const sheets = [{
65
- name: 'Sheet Name Here 1',
66
- // from: {}
67
- }] as SheetOptions[];
68
-
69
- assert.throws(() => {
70
- ExcellentExport.convert(options, sheets)
71
- }, Error);
72
-
73
- });
74
-
75
- it('should fail if there is not format defined', function() {
76
- const options = {
77
- anchor: 'anchor',
78
- filename: 'data_from_array',
79
- //format: 'csv'
80
- } as ConvertOptions;
81
-
82
- const sheets = [{
83
- name: 'Sheet Name Here 1',
84
- from: {}
85
- }];
86
-
87
- assert.throws(() => {
88
- ExcellentExport.convert(options, sheets)
89
- }, Error);
90
-
91
- });
92
-
93
- it('should fail if anchor is not defined/valid', function() {
94
- const options = {
95
- anchor: 'anchor1235d5d5d5d_invalid',
96
- filename: 'data_from_array',
97
- format: 'csv'
98
- } as ConvertOptions;
99
-
100
- const sheets = [{
101
- name: 'Sheet Name Here 1',
102
- from: {}
103
- }];
104
-
105
- assert.throws(() => {
106
- ExcellentExport.convert(options, sheets)
107
- }, Error);
108
-
109
- });
110
-
111
- it('should fail if no anchor and not openAsDownload', function() {
112
- const options = {
113
- filename: 'data_from_array',
114
- format: 'csv'
115
- } as ConvertOptions;
116
-
117
- const sheets = [{
118
- name: 'Sheet Name Here 1',
119
- from: {}
120
- }];
121
-
122
- assert.throws(() => {
123
- ExcellentExport.convert(options, sheets)
124
- }, Error);
125
-
126
- });
127
- });
128
- });
129
-
1
+
2
+ import { describe, expect, test, beforeEach, it, assert } from 'vitest'
3
+
4
+ import ExcellentExport, { ConvertOptions, SheetOptions } from '../src/excellentexport';
5
+
6
+
7
+ describe('convert() API', function() {
8
+ describe('Negative tests', function() {
9
+
10
+ beforeEach(() => {
11
+ window.URL.createObjectURL = () => "blob:fake_URL";
12
+
13
+ const element = document.createElement("div");
14
+ element.innerHTML = '<a id="anchor">Link</a>';
15
+
16
+ document.body.appendChild(element);
17
+ });
18
+
19
+ it('should fail if CSV has more than one sheet', function() {
20
+ const options = {
21
+ anchor: 'anchor',
22
+ filename: 'data_from_array',
23
+ format: 'csv'
24
+ } as ConvertOptions;
25
+
26
+ const sheets = [{
27
+ name: 'Sheet Name Here 1',
28
+ from: {}
29
+ }, {
30
+ name: 'Sheet Number 2',
31
+ from: {}
32
+ }];
33
+
34
+ assert.throws(() => {
35
+ ExcellentExport.convert(options, sheets)
36
+ }, Error);
37
+
38
+ });
39
+
40
+ it('should fail if sheet does not have name', function() {
41
+ const options = {
42
+ anchor: 'anchor',
43
+ filename: 'data_from_array',
44
+ format: 'csv'
45
+ } as ConvertOptions;
46
+
47
+ const sheets = [{
48
+ // name: 'Sheet Name Here 1',
49
+ from: {}
50
+ }] as SheetOptions[];
51
+
52
+ assert.throws(() => {
53
+ ExcellentExport.convert(options, sheets)
54
+ }, Error);
55
+
56
+ });
57
+
58
+ it('should fail if sheet does not have data', function() {
59
+ const options = {
60
+ anchor: 'anchor',
61
+ filename: 'data_from_array',
62
+ format: 'csv'
63
+ } as ConvertOptions;
64
+
65
+ const sheets = [{
66
+ name: 'Sheet Name Here 1',
67
+ // from: {}
68
+ }] as SheetOptions[];
69
+
70
+ assert.throws(() => {
71
+ ExcellentExport.convert(options, sheets)
72
+ }, Error);
73
+
74
+ });
75
+
76
+ it('should fail if there is not format defined', function() {
77
+ const options = {
78
+ anchor: 'anchor',
79
+ filename: 'data_from_array',
80
+ //format: 'csv'
81
+ } as ConvertOptions;
82
+
83
+ const sheets = [{
84
+ name: 'Sheet Name Here 1',
85
+ from: {}
86
+ }];
87
+
88
+ assert.throws(() => {
89
+ ExcellentExport.convert(options, sheets)
90
+ }, Error);
91
+
92
+ });
93
+
94
+ it('should fail if anchor is not defined/valid', function() {
95
+ const options = {
96
+ anchor: 'anchor1235d5d5d5d_invalid',
97
+ filename: 'data_from_array',
98
+ format: 'csv'
99
+ } as ConvertOptions;
100
+
101
+ const sheets = [{
102
+ name: 'Sheet Name Here 1',
103
+ from: {}
104
+ }];
105
+
106
+ assert.throws(() => {
107
+ ExcellentExport.convert(options, sheets)
108
+ }, Error);
109
+
110
+ });
111
+
112
+ it('should fail if no anchor and not openAsDownload', function() {
113
+ const options = {
114
+ filename: 'data_from_array',
115
+ format: 'csv'
116
+ } as ConvertOptions;
117
+
118
+ const sheets = [{
119
+ name: 'Sheet Name Here 1',
120
+ from: {}
121
+ }];
122
+
123
+ assert.throws(() => {
124
+ ExcellentExport.convert(options, sheets)
125
+ }, Error);
126
+
127
+ });
128
+ });
129
+ });
130
+
@@ -1,10 +1,11 @@
1
- const assert = require('assert');
2
-
3
- describe('Array', function() {
4
- describe('#indexOf()', function() {
5
- it('should return -1 when the value is not present', function() {
6
- assert.equal(-1, [1,2,3].indexOf(4));
7
- });
8
- });
9
- });
10
-
1
+ import { describe, expect, test, beforeEach, it, assert } from 'vitest'
2
+
3
+
4
+ describe('Array', function() {
5
+ describe('#indexOf()', function() {
6
+ it('should return -1 when the value is not present', function() {
7
+ assert.equal(-1, [1,2,3].indexOf(4));
8
+ });
9
+ });
10
+ });
11
+
@@ -0,0 +1,19 @@
1
+ {
2
+ "extends": "../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "..",
5
+ "noEmit": true,
6
+ "types": ["node"],
7
+ "module": "commonjs",
8
+ "moduleResolution": "bundler",
9
+ "verbatimModuleSyntax": false,
10
+ "lib": ["ESNext", "DOM"],
11
+ "paths": {
12
+ "@/*": ["../src/*"]
13
+ }
14
+ },
15
+ "include": [
16
+ "../src/**/*.ts",
17
+ "./**/*.ts"
18
+ ]
19
+ }
@@ -1,29 +1,101 @@
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
- });
1
+ import { describe, expect, test, beforeEach, it, assert } from 'vitest'
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
+
30
+ describe('parseTable', () => {
31
+ function makeTable(html: string): HTMLTableElement {
32
+ const div = document.createElement('div');
33
+ div.innerHTML = html;
34
+ return div.querySelector('table') as HTMLTableElement;
35
+ }
36
+
37
+ it('should parse a simple table with no spans', () => {
38
+ const table = makeTable('<table><tr><td>A</td><td>B</td></tr><tr><td>C</td><td>D</td></tr></table>');
39
+ const { data, merges } = utils.parseTable(table);
40
+ expect(data).toEqual([['A', 'B'], ['C', 'D']]);
41
+ expect(merges).toHaveLength(0);
42
+ });
43
+
44
+ it('should handle a cell with colspan=2', () => {
45
+ // Row 0: [Header (colspan=2)], Row 1: [A, B]
46
+ const table = makeTable(
47
+ '<table>' +
48
+ '<tr><td colspan="2">Header</td></tr>' +
49
+ '<tr><td>A</td><td>B</td></tr>' +
50
+ '</table>'
51
+ );
52
+ const { data, merges } = utils.parseTable(table);
53
+ // Header spans columns 0 and 1; second slot should be empty
54
+ expect(data[0][0]).toBe('Header');
55
+ expect(data[0][1]).toBe('');
56
+ expect(data[1]).toEqual(['A', 'B']);
57
+ expect(merges).toHaveLength(1);
58
+ expect(merges[0]).toEqual({ s: { r: 0, c: 0 }, e: { r: 0, c: 1 } });
59
+ });
60
+
61
+ it('should handle a cell with rowspan=2', () => {
62
+ // Row 0: [Side (rowspan=2), Top], Row 1: [Bottom]
63
+ const table = makeTable(
64
+ '<table>' +
65
+ '<tr><td rowspan="2">Side</td><td>Top</td></tr>' +
66
+ '<tr><td>Bottom</td></tr>' +
67
+ '</table>'
68
+ );
69
+ const { data, merges } = utils.parseTable(table);
70
+ expect(data[0][0]).toBe('Side');
71
+ expect(data[0][1]).toBe('Top');
72
+ // Column 0 of row 1 is occupied by rowspan; Bottom goes to column 1
73
+ expect(data[1][0]).toBe('');
74
+ expect(data[1][1]).toBe('Bottom');
75
+ expect(merges).toHaveLength(1);
76
+ expect(merges[0]).toEqual({ s: { r: 0, c: 0 }, e: { r: 1, c: 0 } });
77
+ });
78
+
79
+ it('should handle a cell with both colspan=2 and rowspan=2', () => {
80
+ // 3x3 table, top-left cell spans 2 cols and 2 rows
81
+ const table = makeTable(
82
+ '<table>' +
83
+ '<tr><td colspan="2" rowspan="2">Big</td><td>R0C2</td></tr>' +
84
+ '<tr><td>R1C2</td></tr>' +
85
+ '<tr><td>R2C0</td><td>R2C1</td><td>R2C2</td></tr>' +
86
+ '</table>'
87
+ );
88
+ const { data, merges } = utils.parseTable(table);
89
+ expect(data[0][0]).toBe('Big');
90
+ expect(data[0][1]).toBe('');
91
+ expect(data[0][2]).toBe('R0C2');
92
+ expect(data[1][0]).toBe('');
93
+ expect(data[1][1]).toBe('');
94
+ expect(data[1][2]).toBe('R1C2');
95
+ expect(data[2]).toEqual(['R2C0', 'R2C1', 'R2C2']);
96
+ expect(merges).toHaveLength(1);
97
+ expect(merges[0]).toEqual({ s: { r: 0, c: 0 }, e: { r: 1, c: 1 } });
98
+ });
99
+ });
100
+ });
101
+
@@ -1,24 +1,25 @@
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
- });
1
+ import { describe, expect, test, beforeEach, it, assert } from 'vitest'
2
+
3
+ import { fixCSVField } from '../src/utils';
4
+
5
+
6
+
7
+ describe('Test utility functions: csv functions', () => {
8
+
9
+ it('should keep the value if not delimiter found', () => {
10
+ assert.equal(fixCSVField('test', ','), 'test');
11
+ });
12
+
13
+ it('should fix a string with double quotes', () => {
14
+ const str = 'aaa"bbb';
15
+ const result = fixCSVField(str, "\"");
16
+ assert.equal(result, '\"aaa\"\"bbb\"');
17
+ });
18
+
19
+ it('should fix a field with space delimiter', () => {
20
+ const str = 'aaa bbb';
21
+ const result = fixCSVField(str, " ");
22
+ assert.equal(result, '\"aaa bbb\"');
23
+ });
24
+
25
+ });