read-excel-file 4.0.5 → 4.1.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.
Files changed (42) hide show
  1. package/.gitlab-ci.yml +15 -0
  2. package/CHANGELOG.md +27 -0
  3. package/LICENSE +1 -1
  4. package/README.md +110 -17
  5. package/bundle/index.html +22 -16
  6. package/bundle/read-excel-file.min.js +2 -2
  7. package/bundle/read-excel-file.min.js.map +1 -1
  8. package/commonjs/convertMapToSchema.js +41 -0
  9. package/commonjs/convertMapToSchema.js.map +1 -0
  10. package/commonjs/convertMapToSchema.test.js.map +1 -0
  11. package/commonjs/convertToJson.js +19 -9
  12. package/commonjs/convertToJson.js.map +1 -1
  13. package/commonjs/convertToJson.test.js.map +1 -1
  14. package/commonjs/readXlsx.js +6 -3
  15. package/commonjs/readXlsx.js.map +1 -1
  16. package/commonjs/readXlsxFileContents.js +17 -4
  17. package/commonjs/readXlsxFileContents.js.map +1 -1
  18. package/commonjs/readXlsxFileNode.test.js.map +1 -1
  19. package/index.d.ts.test +20 -0
  20. package/modules/convertMapToSchema.js +34 -0
  21. package/modules/convertMapToSchema.js.map +1 -0
  22. package/modules/convertMapToSchema.test.js.map +1 -0
  23. package/modules/convertToJson.js +19 -9
  24. package/modules/convertToJson.js.map +1 -1
  25. package/modules/convertToJson.test.js.map +1 -1
  26. package/modules/readXlsx.js +6 -3
  27. package/modules/readXlsx.js.map +1 -1
  28. package/modules/readXlsxFileContents.js +14 -4
  29. package/modules/readXlsxFileContents.js.map +1 -1
  30. package/modules/readXlsxFileNode.test.js.map +1 -1
  31. package/node/index.commonjs.js +6 -0
  32. package/node/index.d.ts.test +23 -0
  33. package/node/index.js +5 -0
  34. package/node/package.json +9 -0
  35. package/package.json +7 -6
  36. package/schema/index.commonjs.js +2 -0
  37. package/schema/index.d.ts.test +6 -0
  38. package/schema/index.js +1 -0
  39. package/schema/package.json +9 -0
  40. package/types.d.ts +80 -0
  41. package/website/index.html +105 -0
  42. package/node.js +0 -6
@@ -0,0 +1 @@
1
+ export { default as default } from '../modules/convertToJson'
@@ -0,0 +1,9 @@
1
+ {
2
+ "private": true,
3
+ "name": "read-excel-file-schema",
4
+ "version": "1.0.0",
5
+ "main": "index.commonjs.js",
6
+ "module": "index.js",
7
+ "types.test": "./index.d.ts.test",
8
+ "sideEffects": false
9
+ }
package/types.d.ts ADDED
@@ -0,0 +1,80 @@
1
+ // See the discussion:
2
+ // https://github.com/catamphetamine/read-excel-file/issues/71
3
+
4
+ export function Integer(): void;
5
+ export function URL(): void;
6
+ export function Email(): void;
7
+
8
+ type BasicType =
9
+ | string
10
+ | number
11
+ | boolean
12
+ | typeof Date
13
+ | 'Integer'
14
+ | 'URL'
15
+ | 'Email'
16
+ | Integer
17
+ | URL
18
+ | Email
19
+
20
+ export type Type = <T>(value: Cell) => T?;
21
+
22
+ interface SchemaEntryBasic {
23
+ prop: string;
24
+ type?: BasicType | Type;
25
+ oneOf?<T>: T[];
26
+ required?: boolean;
27
+ validate?<T>(value: T): void;
28
+ }
29
+
30
+ interface SchemaEntryParsed {
31
+ prop: string;
32
+ parse<T>: (value: Cell) => T?;
33
+ oneOf?<T>: T[];
34
+ required?: boolean;
35
+ validate?<T>(value: T): void;
36
+ }
37
+
38
+ // Implementing recursive types in TypeScript:
39
+ // https://dev.to/busypeoples/notes-on-typescript-recursive-types-and-immutability-5ck1
40
+ interface SchemaEntryRecursive {
41
+ prop: string;
42
+ type: Record<string, SchemaEntry>;
43
+ required?: boolean;
44
+ }
45
+
46
+ type SchemaEntry = SchemaEntryBasic | SchemaEntryParsed | SchemaEntryRecursive
47
+
48
+ export type Schema = Record<string, SchemaEntry>
49
+
50
+ export interface Error {
51
+ error: string;
52
+ row: number;
53
+ column: number;
54
+ value?: any;
55
+ type?: SchemaEntry;
56
+ };
57
+
58
+ type Cell = string | number | boolean | typeof Date
59
+ export type Row = Cell[]
60
+
61
+ export interface ParsedObjectsResult {
62
+ rows: object[];
63
+ errors: Error[];
64
+ }
65
+
66
+ export interface ParseWithSchemaOptions {
67
+ schema: Schema;
68
+ transformData?: (rows: Row[]) => Row[];
69
+ sheet?: number | string;
70
+ }
71
+
72
+ export interface ParseWithMapOptions {
73
+ map: object;
74
+ transformData?: (rows: Row[]) => Row[];
75
+ sheet?: number | string;
76
+ }
77
+
78
+ export interface ParseWithoutSchemaOptions {
79
+ sheet?: number | string;
80
+ }
@@ -0,0 +1,105 @@
1
+ <html>
2
+ <head>
3
+ <title>read-excel-file</title>
4
+
5
+ <meta charset="utf-8">
6
+
7
+ <script src="./read-excel-file.min.js"></script>
8
+
9
+ <style>
10
+ body
11
+ {
12
+ margin : 20px;
13
+ font-family : Arial, Helvetica;
14
+ }
15
+
16
+ #input
17
+ {
18
+ margin-top : 20px;
19
+ margin-bottom : 10px;
20
+ }
21
+
22
+
23
+ #result-table table
24
+ {
25
+ width : 100%;
26
+ border-collapse : collapse;
27
+ margin-top : 2.5em;
28
+ margin-bottom : 2.5em;
29
+ font-size : 12px;
30
+ }
31
+
32
+ #result-table table td
33
+ {
34
+ border : 1px solid black;
35
+ padding : 0.5em;
36
+
37
+ text-overflow : ellipsis;
38
+ overflow : hidden;
39
+ max-width : 10em;
40
+ white-space : nowrap;
41
+ }
42
+
43
+ #main-link
44
+ {
45
+ display : block;
46
+ font-size : 24px;
47
+ color : #0093C4;
48
+ font-family : monospace;
49
+ text-decoration : none;
50
+ }
51
+ </style>
52
+ </head>
53
+
54
+ <body>
55
+ <a id="main-link" href="https://gitlab.com/catamphetamine/read-excel-file">
56
+ read-excel-file
57
+ </a>
58
+
59
+ <input type="file" id="input" />
60
+
61
+ <div style="font-size: 12px">
62
+ * Parsing to JSON with a strict schema is supported. <a target="_blank" href="https://gitlab.com/catamphetamine/read-excel-file#json" style="color: #0093C4; text-decoration: none">Read more</a>.
63
+ </div>
64
+
65
+ <div id="result-table"></div>
66
+
67
+ <pre id="result"></pre>
68
+
69
+ <script>
70
+ var input = document.getElementById('input')
71
+
72
+ input.addEventListener('change', function() {
73
+ readXlsxFile(input.files[0], { dateFormat: 'MM/DD/YY' }).then(function(data) {
74
+ // `data` is an array of rows
75
+ // each row being an array of cells.
76
+ document.getElementById('result').innerText = JSON.stringify(data, null, 2)
77
+
78
+ // Applying `innerHTML` hangs the browser when there're a lot of rows/columns.
79
+ // For example, for a file having 2000 rows and 20 columns on a modern
80
+ // mid-tier CPU it parses the file (using a "schema") for 3 seconds
81
+ // (blocking) with 100% single CPU core usage.
82
+ // Then applying `innerHTML` hangs the browser.
83
+
84
+ // document.getElementById('result-table').innerHTML =
85
+ // '<table>' +
86
+ // '<tbody>' +
87
+ // data.map(function (row) {
88
+ // return '<tr>' +
89
+ // row.map(function (cell) {
90
+ // return '<td>' +
91
+ // (cell === null ? '' : cell) +
92
+ // '</td>'
93
+ // }).join('') +
94
+ // '</tr>'
95
+ // }).join('') +
96
+ // '</tbody>' +
97
+ // '</table>'
98
+ }, function (error) {
99
+ console.error(error)
100
+ alert("Error while parsing Excel file. See console output for the error stack trace.")
101
+ })
102
+ })
103
+ </script>
104
+ </body>
105
+ </html>
package/node.js DELETED
@@ -1,6 +0,0 @@
1
- exports = module.exports = require('./commonjs/readXlsxFileNode').default
2
- exports.Integer = require('./commonjs/types/Integer').default
3
- exports.Email = require('./commonjs/types/Email').default
4
- exports.URL = require('./commonjs/types/URL').default
5
- exports.parseExcelDate = require('./commonjs/parseDate').default
6
- exports['default'] = require('./commonjs/readXlsxFileNode').default