@loaders.gl/excel 3.1.0-alpha.4 → 3.1.0-beta.3

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.
@@ -0,0 +1,22 @@
1
+ import type { LoaderWithParser } from '@loaders.gl/loader-utils';
2
+ import { ExcelLoader as ExcelWorkerLoader, ExcelLoaderOptions } from './excel-loader';
3
+ export type { ExcelLoaderOptions };
4
+ export { ExcelWorkerLoader };
5
+ /**
6
+ * Loader for Excel files
7
+ */
8
+ export declare const ExcelLoader: {
9
+ parse: (arrayBuffer: ArrayBuffer, options?: ExcelLoaderOptions | undefined) => Promise<never[]>;
10
+ name: string;
11
+ id: string;
12
+ module: string;
13
+ version: any;
14
+ worker: boolean;
15
+ extensions: string[];
16
+ mimeTypes: string[];
17
+ category: string;
18
+ binary: boolean;
19
+ options: ExcelLoaderOptions;
20
+ };
21
+ export declare const _typecheckLoader: LoaderWithParser;
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAC,WAAW,IAAI,iBAAiB,EAAE,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AAKpF,YAAY,EAAC,kBAAkB,EAAC,CAAC;AACjC,OAAO,EAAC,iBAAiB,EAAC,CAAC;AAE3B;;GAEG;AACH,eAAO,MAAM,WAAW;yBAED,WAAW;;;;;;;;;;;CAEjC,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,gBAA8B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._typecheckLoader = exports.ExcelLoader = exports.ExcelWorkerLoader = void 0;
4
+ const excel_loader_1 = require("./excel-loader");
5
+ Object.defineProperty(exports, "ExcelWorkerLoader", { enumerable: true, get: function () { return excel_loader_1.ExcelLoader; } });
6
+ const parse_excel_1 = require("./lib/parse-excel");
7
+ /**
8
+ * Loader for Excel files
9
+ */
10
+ exports.ExcelLoader = {
11
+ ...excel_loader_1.ExcelLoader,
12
+ parse: (arrayBuffer, options) => (0, parse_excel_1.parseExcel)(arrayBuffer, options)
13
+ };
14
+ exports._typecheckLoader = exports.ExcelLoader;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Saves JSON data in Excel format for html, ods, xml, xlsb and xlsx file types.
3
+ * @param filePath Local data file path.
4
+ * @param fileData Raw data to save.
5
+ * @param tableName Table name for data files with multiple tables support.
6
+ * @param showData Show saved data callback.
7
+ *
8
+ public saveData(filePath: string, fileData: any, tableName: string, showData?: Function): void {
9
+ const fileType: string = filePath.substr(filePath.lastIndexOf('.'));
10
+ fileData = this.jsonToExcelData(fileData, fileType, tableName);
11
+ if ( fileData.length > 0) {
12
+ // TODO: change this to async later
13
+ fs.writeFile(filePath, fileData, (error) => showData(error));
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Converts JSON data to Excel data formats.
19
+ * @param jsonData Json data to convert.
20
+ * @param bookType Excel data file/book type.
21
+ *
22
+ private jsonToExcelData(jsonData: any, fileType: string, tableName: string): any {
23
+ console.debug('jsonToExcelData(): creating excel data:', fileType);
24
+
25
+ // create new workbook
26
+ const workbook = xlsx.utils.book_new();
27
+
28
+ // convert json data to worksheet format
29
+ const worksheet = xlsx.utils.json_to_sheet(jsonData, {
30
+ //header: JSON.parse(this._viewConfig.columns)
31
+ });
32
+
33
+ // append worksheet to workbook
34
+ xlsx.utils.book_append_sheet(workbook, worksheet, tableName);
35
+
36
+ // get text data string or binary spreadsheet data buffer
37
+ let data: any = '';
38
+ if (fileType === 'html' || fileType === 'xml') {
39
+ data = xlsx.write(workbook, {
40
+ type: 'string',
41
+ compression: false,
42
+ bookType: getBookType(fileType)
43
+ });
44
+ } else {
45
+ data = xlsx.write(workbook, {
46
+ type: 'buffer',
47
+ compression: true, // use zip compression for zip-based formats
48
+ bookType: getBookType(fileType)
49
+ });
50
+ }
51
+ return data;
52
+ }
53
+
54
+
55
+ }
56
+
57
+ /**
58
+ * Converts file type to Excel book type.
59
+ * @param {string} fileType File type: .html, .ods, .xml, .xlsb, .xlsx, etc.
60
+ * @returns {xlsx.BookType}
61
+ *
62
+ function getBookType(fileType) {
63
+ // TODO: must be a better way to do this string to type conversion :)
64
+ switch (fileType) {
65
+ case '.html':
66
+ return 'html';
67
+ case '.ods':
68
+ return 'ods';
69
+ case '.xml':
70
+ return 'xlml';
71
+ case '.xlsb':
72
+ return 'xlsb';
73
+ case '.xlsx':
74
+ return 'xlsx';
75
+ default:
76
+ return 'xlsb';
77
+ }
78
+ }
79
+ */
80
+ //# sourceMappingURL=encode-excel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-excel.d.ts","sourceRoot":"","sources":["../../src/lib/encode-excel.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8EE"}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ // import * as xlsx from 'xlsx';
3
+ /**
4
+ * Saves JSON data in Excel format for html, ods, xml, xlsb and xlsx file types.
5
+ * @param filePath Local data file path.
6
+ * @param fileData Raw data to save.
7
+ * @param tableName Table name for data files with multiple tables support.
8
+ * @param showData Show saved data callback.
9
+ *
10
+ public saveData(filePath: string, fileData: any, tableName: string, showData?: Function): void {
11
+ const fileType: string = filePath.substr(filePath.lastIndexOf('.'));
12
+ fileData = this.jsonToExcelData(fileData, fileType, tableName);
13
+ if ( fileData.length > 0) {
14
+ // TODO: change this to async later
15
+ fs.writeFile(filePath, fileData, (error) => showData(error));
16
+ }
17
+ }
18
+
19
+ /**
20
+ * Converts JSON data to Excel data formats.
21
+ * @param jsonData Json data to convert.
22
+ * @param bookType Excel data file/book type.
23
+ *
24
+ private jsonToExcelData(jsonData: any, fileType: string, tableName: string): any {
25
+ console.debug('jsonToExcelData(): creating excel data:', fileType);
26
+
27
+ // create new workbook
28
+ const workbook = xlsx.utils.book_new();
29
+
30
+ // convert json data to worksheet format
31
+ const worksheet = xlsx.utils.json_to_sheet(jsonData, {
32
+ //header: JSON.parse(this._viewConfig.columns)
33
+ });
34
+
35
+ // append worksheet to workbook
36
+ xlsx.utils.book_append_sheet(workbook, worksheet, tableName);
37
+
38
+ // get text data string or binary spreadsheet data buffer
39
+ let data: any = '';
40
+ if (fileType === 'html' || fileType === 'xml') {
41
+ data = xlsx.write(workbook, {
42
+ type: 'string',
43
+ compression: false,
44
+ bookType: getBookType(fileType)
45
+ });
46
+ } else {
47
+ data = xlsx.write(workbook, {
48
+ type: 'buffer',
49
+ compression: true, // use zip compression for zip-based formats
50
+ bookType: getBookType(fileType)
51
+ });
52
+ }
53
+ return data;
54
+ }
55
+
56
+
57
+ }
58
+
59
+ /**
60
+ * Converts file type to Excel book type.
61
+ * @param {string} fileType File type: .html, .ods, .xml, .xlsb, .xlsx, etc.
62
+ * @returns {xlsx.BookType}
63
+ *
64
+ function getBookType(fileType) {
65
+ // TODO: must be a better way to do this string to type conversion :)
66
+ switch (fileType) {
67
+ case '.html':
68
+ return 'html';
69
+ case '.ods':
70
+ return 'ods';
71
+ case '.xml':
72
+ return 'xlml';
73
+ case '.xlsb':
74
+ return 'xlsb';
75
+ case '.xlsx':
76
+ return 'xlsx';
77
+ default:
78
+ return 'xlsb';
79
+ }
80
+ }
81
+ */
@@ -0,0 +1,8 @@
1
+ import type { ExcelLoaderOptions } from '../excel-loader';
2
+ /**
3
+ * Gets local or remote Excel file data.
4
+ * @param arrayBuffer Loaded data
5
+ * @param options Data parse options.
6
+ */
7
+ export declare function parseExcel(arrayBuffer: ArrayBuffer, options?: ExcelLoaderOptions): Promise<never[]>;
8
+ //# sourceMappingURL=parse-excel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-excel.d.ts","sourceRoot":"","sources":["../../src/lib/parse-excel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAOxD;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,kBAAkB,oBAuCtF"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseExcel = void 0;
4
+ const xlsx_1 = require("xlsx");
5
+ // import {convertToArrayRow} from '@loaders.gl/schema';
6
+ // local table names cache with dataUrl/tableNames array key/values
7
+ const dataTableNamesMap = {};
8
+ /**
9
+ * Gets local or remote Excel file data.
10
+ * @param arrayBuffer Loaded data
11
+ * @param options Data parse options.
12
+ */
13
+ async function parseExcel(arrayBuffer, options) {
14
+ const dataUrl = 'dummy';
15
+ // const dataFileType: string = dataUrl.substr(dataUrl.lastIndexOf('.')); // file extension
16
+ // create Excel 'workbook'
17
+ const workbook = (0, xlsx_1.read)(arrayBuffer, {
18
+ type: 'array'
19
+ // cellDates: true
20
+ });
21
+ // load data sheets
22
+ let dataRows = [];
23
+ dataTableNamesMap[dataUrl] = [];
24
+ if (workbook.SheetNames.length > 0) {
25
+ if (workbook.SheetNames.length > 1) {
26
+ // cache sheet names
27
+ dataTableNamesMap[dataUrl] = workbook.SheetNames;
28
+ // eslint-ignore-next-line
29
+ // console.debug(`getData(): file: sheetNames:`, workbook.SheetNames);
30
+ }
31
+ // determine spreadsheet to load
32
+ let sheetName = workbook.SheetNames[0];
33
+ if (options?.excel?.sheet && workbook.SheetNames.indexOf(options?.excel?.sheet) >= 0) {
34
+ // reset to requested table name
35
+ sheetName = options?.excel?.sheet;
36
+ }
37
+ // get worksheet data row objects array
38
+ const worksheet = workbook.Sheets[sheetName];
39
+ dataRows = xlsx_1.utils.sheet_to_json(worksheet);
40
+ // const headers = dataRows.length ? Object.keys(dataRows[0]) : [];
41
+ // if (options?.excel?.type === 'array-row-table') {
42
+ // dataRows = dataRows.map(row => convertToArrayRow(row, headers))
43
+ // }
44
+ }
45
+ return dataRows;
46
+ }
47
+ exports.parseExcel = parseExcel;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=excel-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excel-worker.d.ts","sourceRoot":"","sources":["../../src/workers/excel-worker.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const loader_utils_1 = require("@loaders.gl/loader-utils");
4
+ const index_1 = require("../index");
5
+ (0, loader_utils_1.createLoaderWorker)(index_1.ExcelLoader);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/excel",
3
- "version": "3.1.0-alpha.4",
3
+ "version": "3.1.0-beta.3",
4
4
  "description": "Framework-independent loader for Excel files",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -20,7 +20,7 @@
20
20
  "Worksheets",
21
21
  "Spreadsheets"
22
22
  ],
23
- "types": "src/index.ts",
23
+ "types": "dist/index.d.ts",
24
24
  "main": "dist/es5/index.js",
25
25
  "module": "dist/esm/index.js",
26
26
  "sideEffects": false,
@@ -31,13 +31,13 @@
31
31
  ],
32
32
  "scripts": {
33
33
  "pre-build": "npm run build-bundle && npm run build-worker",
34
- "build-bundle": "webpack --display=minimal --config ../../scripts/webpack/bundle.js",
35
- "build-worker": "webpack --entry ./src/workers/excel-worker.ts --output ./dist/excel-worker.js --config ../../scripts/webpack/worker.js"
34
+ "build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js",
35
+ "build-worker": "esbuild src/workers/excel-worker.ts --bundle --outfile=dist/excel-worker.js"
36
36
  },
37
37
  "dependencies": {
38
- "@loaders.gl/loader-utils": "3.1.0-alpha.4",
39
- "@loaders.gl/schema": "3.1.0-alpha.4",
38
+ "@loaders.gl/loader-utils": "3.1.0-beta.3",
39
+ "@loaders.gl/schema": "3.1.0-beta.3",
40
40
  "xlsx": "^0.17.0"
41
41
  },
42
- "gitHead": "e309784af37ef9f3640c7733c7851124c72e1fa3"
42
+ "gitHead": "3537c382b3ea4e092b24b6f94c3edee72076039c"
43
43
  }