@loaders.gl/excel 4.0.0-alpha.4 → 4.0.0-alpha.5
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/dist.min.js +34714 -0
- package/dist/excel-loader.d.ts +24 -0
- package/dist/excel-loader.d.ts.map +1 -0
- package/dist/excel-loader.js +1 -1
- package/dist/excel-worker.js +1 -1
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lib/encode-excel.d.ts +80 -0
- package/dist/lib/encode-excel.d.ts.map +1 -0
- package/dist/lib/parse-excel.d.ts +8 -0
- package/dist/lib/parse-excel.d.ts.map +1 -0
- package/dist/workers/excel-worker.d.ts +2 -0
- package/dist/workers/excel-worker.d.ts.map +1 -0
- package/package.json +7 -7
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Loader, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
export declare type ExcelLoaderOptions = LoaderOptions & {
|
|
3
|
+
excel?: {
|
|
4
|
+
shape: 'object-row-table';
|
|
5
|
+
sheet?: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Worker Loader for Excel files
|
|
10
|
+
*/
|
|
11
|
+
export declare const ExcelLoader: {
|
|
12
|
+
name: string;
|
|
13
|
+
id: string;
|
|
14
|
+
module: string;
|
|
15
|
+
version: any;
|
|
16
|
+
worker: boolean;
|
|
17
|
+
extensions: string[];
|
|
18
|
+
mimeTypes: string[];
|
|
19
|
+
category: string;
|
|
20
|
+
binary: boolean;
|
|
21
|
+
options: ExcelLoaderOptions;
|
|
22
|
+
};
|
|
23
|
+
export declare const _typecheckLoader: Loader;
|
|
24
|
+
//# sourceMappingURL=excel-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excel-loader.d.ts","sourceRoot":"","sources":["../src/excel-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAMpE,oBAAY,kBAAkB,GAAG,aAAa,GAAG;IAC/C,KAAK,CAAC,EAAE;QACN,KAAK,EAA4B,kBAAkB,CAAC;QACpD,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC;AASF;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;CAcvB,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,MAAoB,CAAC"}
|
package/dist/excel-loader.js
CHANGED
package/dist/excel-worker.js
CHANGED
|
@@ -34768,7 +34768,7 @@
|
|
|
34768
34768
|
}
|
|
34769
34769
|
|
|
34770
34770
|
// src/excel-loader.ts
|
|
34771
|
-
var VERSION =
|
|
34771
|
+
var VERSION = true ? "4.0.0-alpha.5" : "latest";
|
|
34772
34772
|
var DEFAULT_EXCEL_LOADER_OPTIONS = {
|
|
34773
34773
|
excel: {
|
|
34774
34774
|
shape: "object-row-table",
|
package/dist/index.d.ts
ADDED
|
@@ -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"}
|
|
@@ -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,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 @@
|
|
|
1
|
+
{"version":3,"file":"excel-worker.d.ts","sourceRoot":"","sources":["../../src/workers/excel-worker.ts"],"names":[],"mappings":""}
|
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.5",
|
|
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": "
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
24
|
"main": "dist/index.js",
|
|
25
25
|
"module": "dist/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": "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.5",
|
|
39
|
+
"@loaders.gl/schema": "4.0.0-alpha.5",
|
|
40
40
|
"xlsx": "^0.17.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "7a71a54bdf1ddf985cc3af3db90b82e7fa97d025"
|
|
43
43
|
}
|