@loaders.gl/excel 4.0.0-alpha.4 → 4.0.0-alpha.6
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/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +2 -2
- package/dist/dist.min.js +35871 -0
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/excel-loader.js +29 -0
- package/dist/es5/excel-loader.js.map +1 -0
- package/dist/es5/index.js +42 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/encode-excel.js +2 -0
- package/dist/es5/lib/encode-excel.js.map +1 -0
- package/dist/es5/lib/parse-excel.js +31 -0
- package/dist/es5/lib/parse-excel.js.map +1 -0
- package/dist/es5/workers/excel-worker.js +6 -0
- package/dist/es5/workers/excel-worker.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/excel-loader.js +21 -0
- package/dist/esm/excel-loader.js.map +1 -0
- package/dist/esm/index.js +14 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/encode-excel.js +2 -0
- package/dist/esm/lib/encode-excel.js.map +1 -0
- package/dist/esm/lib/parse-excel.js +25 -0
- package/dist/esm/lib/parse-excel.js.map +1 -0
- package/dist/esm/workers/excel-worker.js +4 -0
- package/dist/esm/workers/excel-worker.js.map +1 -0
- package/dist/excel-loader.d.ts +14 -0
- package/dist/excel-loader.d.ts.map +1 -0
- package/dist/excel-loader.js +29 -18
- package/dist/excel-worker.js +1502 -311
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -7
- package/dist/lib/encode-excel.d.ts +80 -0
- package/dist/lib/encode-excel.d.ts.map +1 -0
- package/dist/lib/encode-excel.js +80 -1
- package/dist/lib/parse-excel.d.ts +10 -0
- package/dist/lib/parse-excel.d.ts.map +1 -0
- package/dist/lib/parse-excel.js +44 -29
- package/dist/workers/excel-worker.d.ts +2 -0
- package/dist/workers/excel-worker.d.ts.map +1 -0
- package/dist/workers/excel-worker.js +5 -4
- package/package.json +9 -9
- package/src/excel-loader.ts +4 -1
- package/src/index.ts +10 -6
- package/src/lib/parse-excel.ts +5 -2
- package/dist/bundle.js.map +0 -1
- package/dist/excel-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/encode-excel.js.map +0 -1
- package/dist/lib/parse-excel.js.map +0 -1
- package/dist/workers/excel-worker.js.map +0 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { LoaderWithParser } from '@loaders.gl/loader-utils';
|
|
2
|
+
import type { ObjectRowTable } from '@loaders.gl/schema';
|
|
3
|
+
import type { ExcelLoaderOptions } from './excel-loader';
|
|
4
|
+
import { ExcelLoader as ExcelWorkerLoader } from './excel-loader';
|
|
5
|
+
export type { ExcelLoaderOptions };
|
|
6
|
+
export { ExcelWorkerLoader };
|
|
7
|
+
/**
|
|
8
|
+
* Loader for Excel files
|
|
9
|
+
*/
|
|
10
|
+
export declare const ExcelLoader: LoaderWithParser<ObjectRowTable, never, ExcelLoaderOptions>;
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAC,WAAW,IAAI,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAKhE,YAAY,EAAC,kBAAkB,EAAC,CAAC;AACjC,OAAO,EAAC,iBAAiB,EAAC,CAAC;AAE3B;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,gBAAgB,CAAC,cAAc,EAAE,KAAK,EAAE,kBAAkB,CAMnF,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// loaders.gl, MIT license
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ExcelLoader = exports.ExcelWorkerLoader = void 0;
|
|
5
|
+
const excel_loader_1 = require("./excel-loader");
|
|
6
|
+
Object.defineProperty(exports, "ExcelWorkerLoader", { enumerable: true, get: function () { return excel_loader_1.ExcelLoader; } });
|
|
7
|
+
const parse_excel_1 = require("./lib/parse-excel");
|
|
8
|
+
/**
|
|
9
|
+
* Loader for Excel files
|
|
10
|
+
*/
|
|
11
|
+
exports.ExcelLoader = {
|
|
12
|
+
...excel_loader_1.ExcelLoader,
|
|
13
|
+
async parse(arrayBuffer, options) {
|
|
14
|
+
const data = (0, parse_excel_1.parseExcel)(arrayBuffer, options);
|
|
15
|
+
return { shape: 'object-row-table', data };
|
|
16
|
+
}
|
|
6
17
|
};
|
|
7
|
-
export const _typecheckLoader = ExcelLoader;
|
|
8
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -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"}
|
package/dist/lib/encode-excel.js
CHANGED
|
@@ -1,2 +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
|
+
}
|
|
1
18
|
|
|
2
|
-
|
|
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,10 @@
|
|
|
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): {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}[];
|
|
10
|
+
//# 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,wBAAgB,UAAU,CACxB,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,kBAAkB,GAC3B;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,EAAE,CAuC5B"}
|
package/dist/lib/parse-excel.js
CHANGED
|
@@ -1,32 +1,47 @@
|
|
|
1
|
-
|
|
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
|
|
2
7
|
const dataTableNamesMap = {};
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Gets local or remote Excel file data.
|
|
10
|
+
* @param arrayBuffer Loaded data
|
|
11
|
+
* @param options Data parse options.
|
|
12
|
+
*/
|
|
13
|
+
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
|
+
// }
|
|
16
44
|
}
|
|
17
|
-
|
|
18
|
-
let sheetName = workbook.SheetNames[0];
|
|
19
|
-
|
|
20
|
-
if (options !== null && options !== void 0 && (_options$excel = options.excel) !== null && _options$excel !== void 0 && _options$excel.sheet && workbook.SheetNames.indexOf(options === null || options === void 0 ? void 0 : (_options$excel2 = options.excel) === null || _options$excel2 === void 0 ? void 0 : _options$excel2.sheet) >= 0) {
|
|
21
|
-
var _options$excel3;
|
|
22
|
-
|
|
23
|
-
sheetName = options === null || options === void 0 ? void 0 : (_options$excel3 = options.excel) === null || _options$excel3 === void 0 ? void 0 : _options$excel3.sheet;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const worksheet = workbook.Sheets[sheetName];
|
|
27
|
-
dataRows = utils.sheet_to_json(worksheet);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return dataRows;
|
|
45
|
+
return dataRows;
|
|
31
46
|
}
|
|
32
|
-
|
|
47
|
+
exports.parseExcel = parseExcel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excel-worker.d.ts","sourceRoot":"","sources":["../../src/workers/excel-worker.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.6",
|
|
4
4
|
"description": "Framework-independent loader for Excel files",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"Worksheets",
|
|
21
21
|
"Spreadsheets"
|
|
22
22
|
],
|
|
23
|
-
"types": "
|
|
24
|
-
"main": "dist/index.js",
|
|
25
|
-
"module": "dist/index.js",
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
|
+
"main": "dist/es5/index.js",
|
|
25
|
+
"module": "dist/esm/index.js",
|
|
26
26
|
"sideEffects": false,
|
|
27
27
|
"files": [
|
|
28
28
|
"src",
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
33
|
"pre-build": "npm run build-bundle && npm run build-worker",
|
|
34
|
-
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/
|
|
35
|
-
"build-worker": "esbuild src/workers/excel-worker.ts --bundle --outfile=dist/excel-worker.js"
|
|
34
|
+
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js",
|
|
35
|
+
"build-worker": "esbuild src/workers/excel-worker.ts --bundle --outfile=dist/excel-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
39
|
-
"@loaders.gl/schema": "4.0.0-alpha.
|
|
38
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.6",
|
|
39
|
+
"@loaders.gl/schema": "4.0.0-alpha.6",
|
|
40
40
|
"xlsx": "^0.17.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "acc1985050dfaa0f1f0c066f8da5bce7454a046c"
|
|
43
43
|
}
|
package/src/excel-loader.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
1
3
|
import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
4
|
+
import type {ObjectRowTable} from '@loaders.gl/schema';
|
|
2
5
|
|
|
3
6
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
4
7
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
@@ -21,7 +24,7 @@ const DEFAULT_EXCEL_LOADER_OPTIONS: ExcelLoaderOptions = {
|
|
|
21
24
|
/**
|
|
22
25
|
* Worker Loader for Excel files
|
|
23
26
|
*/
|
|
24
|
-
export const ExcelLoader = {
|
|
27
|
+
export const ExcelLoader: Loader<ObjectRowTable, never, ExcelLoaderOptions> = {
|
|
25
28
|
name: 'Excel',
|
|
26
29
|
id: 'excel',
|
|
27
30
|
module: 'excel',
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
1
3
|
import type {LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
2
|
-
import {
|
|
4
|
+
import type {ObjectRowTable} from '@loaders.gl/schema';
|
|
5
|
+
import type {ExcelLoaderOptions} from './excel-loader';
|
|
6
|
+
import {ExcelLoader as ExcelWorkerLoader} from './excel-loader';
|
|
3
7
|
import {parseExcel} from './lib/parse-excel';
|
|
4
8
|
|
|
5
9
|
// Excel Loader
|
|
@@ -10,10 +14,10 @@ export {ExcelWorkerLoader};
|
|
|
10
14
|
/**
|
|
11
15
|
* Loader for Excel files
|
|
12
16
|
*/
|
|
13
|
-
export const ExcelLoader = {
|
|
17
|
+
export const ExcelLoader: LoaderWithParser<ObjectRowTable, never, ExcelLoaderOptions> = {
|
|
14
18
|
...ExcelWorkerLoader,
|
|
15
|
-
parse
|
|
16
|
-
parseExcel(arrayBuffer, options)
|
|
19
|
+
async parse(arrayBuffer: ArrayBuffer, options?: ExcelLoaderOptions): Promise<ObjectRowTable> {
|
|
20
|
+
const data = parseExcel(arrayBuffer, options);
|
|
21
|
+
return {shape: 'object-row-table', data};
|
|
22
|
+
}
|
|
17
23
|
};
|
|
18
|
-
|
|
19
|
-
export const _typecheckLoader: LoaderWithParser = ExcelLoader;
|
package/src/lib/parse-excel.ts
CHANGED
|
@@ -10,7 +10,10 @@ const dataTableNamesMap = {};
|
|
|
10
10
|
* @param arrayBuffer Loaded data
|
|
11
11
|
* @param options Data parse options.
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export function parseExcel(
|
|
14
|
+
arrayBuffer: ArrayBuffer,
|
|
15
|
+
options?: ExcelLoaderOptions
|
|
16
|
+
): {[key: string]: unknown}[] {
|
|
14
17
|
const dataUrl = 'dummy';
|
|
15
18
|
// const dataFileType: string = dataUrl.substr(dataUrl.lastIndexOf('.')); // file extension
|
|
16
19
|
|
|
@@ -21,7 +24,7 @@ export async function parseExcel(arrayBuffer: ArrayBuffer, options?: ExcelLoader
|
|
|
21
24
|
});
|
|
22
25
|
|
|
23
26
|
// load data sheets
|
|
24
|
-
let dataRows = [];
|
|
27
|
+
let dataRows: {[key: string]: unknown}[] = [];
|
|
25
28
|
dataTableNamesMap[dataUrl] = [];
|
|
26
29
|
if (workbook.SheetNames.length > 0) {
|
|
27
30
|
if (workbook.SheetNames.length > 1) {
|
package/dist/bundle.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bundle.ts"],"names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"mappings":"AACA,MAAMA,aAAa,GAAGC,OAAO,CAAC,SAAD,CAA7B;;AACAC,UAAU,CAACC,OAAX,GAAqBD,UAAU,CAACC,OAAX,IAAsB,EAA3C;AACAC,MAAM,CAACC,OAAP,GAAiBC,MAAM,CAACC,MAAP,CAAcL,UAAU,CAACC,OAAzB,EAAkCH,aAAlC,CAAjB","sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"file":"bundle.js"}
|
package/dist/excel-loader.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/excel-loader.ts"],"names":["VERSION","DEFAULT_EXCEL_LOADER_OPTIONS","excel","shape","sheet","undefined","ExcelLoader","name","id","module","version","worker","extensions","mimeTypes","category","binary","options","_typecheckLoader"],"mappings":"AAIA,MAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AASA,MAAMC,4BAAgD,GAAG;AACvDC,EAAAA,KAAK,EAAE;AACLC,IAAAA,KAAK,EAAE,kBADF;AAELC,IAAAA,KAAK,EAAEC;AAFF;AADgD,CAAzD;AAUA,OAAO,MAAMC,WAAW,GAAG;AACzBC,EAAAA,IAAI,EAAE,OADmB;AAEzBC,EAAAA,EAAE,EAAE,OAFqB;AAGzBC,EAAAA,MAAM,EAAE,OAHiB;AAIzBC,EAAAA,OAAO,EAAEV,OAJgB;AAKzBW,EAAAA,MAAM,EAAE,IALiB;AAMzBC,EAAAA,UAAU,EAAE,CAAC,KAAD,EAAQ,MAAR,EAAgB,MAAhB,EAAwB,MAAxB,CANa;AAOzBC,EAAAA,SAAS,EAAE,CACT,mEADS,EAET,0BAFS,CAPc;AAWzBC,EAAAA,QAAQ,EAAE,OAXe;AAYzBC,EAAAA,MAAM,EAAE,IAZiB;AAazBC,EAAAA,OAAO,EAAEf;AAbgB,CAApB;AAgBP,OAAO,MAAMgB,gBAAwB,GAAGX,WAAjC","sourcesContent":["import type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type ExcelLoaderOptions = LoaderOptions & {\n excel?: {\n shape: /* 'array-row-table' | */ 'object-row-table';\n sheet?: string; // Load default Sheet\n };\n};\n\nconst DEFAULT_EXCEL_LOADER_OPTIONS: ExcelLoaderOptions = {\n excel: {\n shape: 'object-row-table',\n sheet: undefined // Load default Sheet\n }\n};\n\n/**\n * Worker Loader for Excel files\n */\nexport const ExcelLoader = {\n name: 'Excel',\n id: 'excel',\n module: 'excel',\n version: VERSION,\n worker: true,\n extensions: ['xls', 'xlsb', 'xlsm', 'xlsx'],\n mimeTypes: [\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',\n 'application/vnd.ms-excel'\n ],\n category: 'table',\n binary: true,\n options: DEFAULT_EXCEL_LOADER_OPTIONS\n};\n\nexport const _typecheckLoader: Loader = ExcelLoader;\n"],"file":"excel-loader.js"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["ExcelLoader","ExcelWorkerLoader","parseExcel","parse","arrayBuffer","options","_typecheckLoader"],"mappings":"AACA,SAAQA,WAAW,IAAIC,iBAAvB,QAAmE,gBAAnE;AACA,SAAQC,UAAR,QAAyB,mBAAzB;AAKA,SAAQD,iBAAR;AAKA,OAAO,MAAMD,WAAW,GAAG,EACzB,GAAGC,iBADsB;AAEzBE,EAAAA,KAAK,EAAE,CAACC,WAAD,EAA2BC,OAA3B,KACLH,UAAU,CAACE,WAAD,EAAcC,OAAd;AAHa,CAApB;AAMP,OAAO,MAAMC,gBAAkC,GAAGN,WAA3C","sourcesContent":["import type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport {ExcelLoader as ExcelWorkerLoader, ExcelLoaderOptions} from './excel-loader';\nimport {parseExcel} from './lib/parse-excel';\n\n// Excel Loader\n\nexport type {ExcelLoaderOptions};\nexport {ExcelWorkerLoader};\n\n/**\n * Loader for Excel files\n */\nexport const ExcelLoader = {\n ...ExcelWorkerLoader,\n parse: (arrayBuffer: ArrayBuffer, options?: ExcelLoaderOptions) =>\n parseExcel(arrayBuffer, options)\n};\n\nexport const _typecheckLoader: LoaderWithParser = ExcelLoader;\n"],"file":"index.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"encode-excel.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/parse-excel.ts"],"names":["utils","read","dataTableNamesMap","parseExcel","arrayBuffer","options","dataUrl","workbook","type","dataRows","SheetNames","length","sheetName","excel","sheet","indexOf","worksheet","Sheets","sheet_to_json"],"mappings":"AACA,SAAQA,KAAR,EAAeC,IAAf,QAA0B,MAA1B;AAIA,MAAMC,iBAAiB,GAAG,EAA1B;AAOA,OAAO,eAAeC,UAAf,CAA0BC,WAA1B,EAAoDC,OAApD,EAAkF;AACvF,QAAMC,OAAO,GAAG,OAAhB;AAIA,QAAMC,QAAQ,GAAGN,IAAI,CAACG,WAAD,EAAc;AACjCI,IAAAA,IAAI,EAAE;AAD2B,GAAd,CAArB;AAMA,MAAIC,QAAQ,GAAG,EAAf;AACAP,EAAAA,iBAAiB,CAACI,OAAD,CAAjB,GAA6B,EAA7B;;AACA,MAAIC,QAAQ,CAACG,UAAT,CAAoBC,MAApB,GAA6B,CAAjC,EAAoC;AAAA;;AAClC,QAAIJ,QAAQ,CAACG,UAAT,CAAoBC,MAApB,GAA6B,CAAjC,EAAoC;AAElCT,MAAAA,iBAAiB,CAACI,OAAD,CAAjB,GAA6BC,QAAQ,CAACG,UAAtC;AAGD;;AAGD,QAAIE,SAAS,GAAGL,QAAQ,CAACG,UAAT,CAAoB,CAApB,CAAhB;;AACA,QAAIL,OAAO,SAAP,IAAAA,OAAO,WAAP,sBAAAA,OAAO,CAAEQ,KAAT,0DAAgBC,KAAhB,IAAyBP,QAAQ,CAACG,UAAT,CAAoBK,OAApB,CAA4BV,OAA5B,aAA4BA,OAA5B,0CAA4BA,OAAO,CAAEQ,KAArC,oDAA4B,gBAAgBC,KAA5C,KAAsD,CAAnF,EAAsF;AAAA;;AAEpFF,MAAAA,SAAS,GAAGP,OAAH,aAAGA,OAAH,0CAAGA,OAAO,CAAEQ,KAAZ,oDAAG,gBAAgBC,KAA5B;AACD;;AAGD,UAAME,SAAS,GAAGT,QAAQ,CAACU,MAAT,CAAgBL,SAAhB,CAAlB;AACAH,IAAAA,QAAQ,GAAGT,KAAK,CAACkB,aAAN,CAAoBF,SAApB,CAAX;AAMD;;AAED,SAAOP,QAAP;AACD","sourcesContent":["import type {ExcelLoaderOptions} from '../excel-loader';\nimport {utils, read} from 'xlsx';\n// import {convertToArrayRow} from '@loaders.gl/schema';\n\n// local table names cache with dataUrl/tableNames array key/values\nconst dataTableNamesMap = {};\n\n/**\n * Gets local or remote Excel file data.\n * @param arrayBuffer Loaded data\n * @param options Data parse options.\n */\nexport async function parseExcel(arrayBuffer: ArrayBuffer, options?: ExcelLoaderOptions) {\n const dataUrl = 'dummy';\n // const dataFileType: string = dataUrl.substr(dataUrl.lastIndexOf('.')); // file extension\n\n // create Excel 'workbook'\n const workbook = read(arrayBuffer, {\n type: 'array'\n // cellDates: true\n });\n\n // load data sheets\n let dataRows = [];\n dataTableNamesMap[dataUrl] = [];\n if (workbook.SheetNames.length > 0) {\n if (workbook.SheetNames.length > 1) {\n // cache sheet names\n dataTableNamesMap[dataUrl] = workbook.SheetNames;\n // eslint-ignore-next-line\n // console.debug(`getData(): file: sheetNames:`, workbook.SheetNames);\n }\n\n // determine spreadsheet to load\n let sheetName = workbook.SheetNames[0];\n if (options?.excel?.sheet && workbook.SheetNames.indexOf(options?.excel?.sheet) >= 0) {\n // reset to requested table name\n sheetName = options?.excel?.sheet;\n }\n\n // get worksheet data row objects array\n const worksheet = workbook.Sheets[sheetName];\n dataRows = utils.sheet_to_json(worksheet);\n\n // const headers = dataRows.length ? Object.keys(dataRows[0]) : [];\n // if (options?.excel?.type === 'array-row-table') {\n // dataRows = dataRows.map(row => convertToArrayRow(row, headers))\n // }\n }\n\n return dataRows;\n}\n"],"file":"parse-excel.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/workers/excel-worker.ts"],"names":["createLoaderWorker","ExcelLoader"],"mappings":"AAAA,SAAQA,kBAAR,QAAiC,0BAAjC;AACA,SAAQC,WAAR,QAA0B,UAA1B;AAEAD,kBAAkB,CAACC,WAAD,CAAlB","sourcesContent":["import {createLoaderWorker} from '@loaders.gl/loader-utils';\nimport {ExcelLoader} from '../index';\n\ncreateLoaderWorker(ExcelLoader);\n"],"file":"excel-worker.js"}
|