@loaders.gl/excel 4.2.0-alpha.4 → 4.2.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.
@@ -1,20 +1,30 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // __VERSION__ is injected by babel-plugin-version-inline
5
+ // @ts-ignore TS2304: Cannot find name '__VERSION__'.
1
6
  const VERSION = typeof "4.2.0-alpha.4" !== 'undefined' ? "4.2.0-alpha.4" : 'latest';
2
7
  const DEFAULT_EXCEL_LOADER_OPTIONS = {
3
- excel: {
4
- shape: 'object-row-table',
5
- sheet: undefined
6
- }
8
+ excel: {
9
+ shape: 'object-row-table',
10
+ sheet: undefined // Load default Sheet
11
+ }
7
12
  };
13
+ /**
14
+ * Worker Loader for Excel files
15
+ */
8
16
  export const ExcelLoader = {
9
- name: 'Excel',
10
- id: 'excel',
11
- module: 'excel',
12
- version: VERSION,
13
- worker: true,
14
- extensions: ['xls', 'xlsb', 'xlsm', 'xlsx'],
15
- mimeTypes: ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel'],
16
- category: 'table',
17
- binary: true,
18
- options: DEFAULT_EXCEL_LOADER_OPTIONS
17
+ name: 'Excel',
18
+ id: 'excel',
19
+ module: 'excel',
20
+ version: VERSION,
21
+ worker: true,
22
+ extensions: ['xls', 'xlsb', 'xlsm', 'xlsx'],
23
+ mimeTypes: [
24
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
25
+ 'application/vnd.ms-excel'
26
+ ],
27
+ category: 'table',
28
+ binary: true,
29
+ options: DEFAULT_EXCEL_LOADER_OPTIONS
19
30
  };
20
- //# sourceMappingURL=excel-loader.js.map
package/dist/index.cjs CHANGED
@@ -17,16 +17,16 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
20
+ // dist/index.js
21
+ var dist_exports = {};
22
+ __export(dist_exports, {
23
23
  ExcelLoader: () => ExcelLoader2,
24
24
  ExcelWorkerLoader: () => ExcelLoader
25
25
  });
26
- module.exports = __toCommonJS(src_exports);
26
+ module.exports = __toCommonJS(dist_exports);
27
27
 
28
- // src/excel-loader.ts
29
- var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
28
+ // dist/excel-loader.js
29
+ var VERSION = true ? "4.2.0-alpha.4" : "latest";
30
30
  var DEFAULT_EXCEL_LOADER_OPTIONS = {
31
31
  excel: {
32
32
  shape: "object-row-table",
@@ -50,7 +50,7 @@ var ExcelLoader = {
50
50
  options: DEFAULT_EXCEL_LOADER_OPTIONS
51
51
  };
52
52
 
53
- // src/lib/parse-excel.ts
53
+ // dist/lib/parse-excel.js
54
54
  var import_xlsx = require("xlsx");
55
55
  var dataTableNamesMap = {};
56
56
  function parseExcel(arrayBuffer, options) {
@@ -76,7 +76,7 @@ function parseExcel(arrayBuffer, options) {
76
76
  return dataRows;
77
77
  }
78
78
 
79
- // src/index.ts
79
+ // dist/index.js
80
80
  var ExcelLoader2 = {
81
81
  ...ExcelLoader,
82
82
  async parse(arrayBuffer, options) {
@@ -84,3 +84,4 @@ var ExcelLoader2 = {
84
84
  return { shape: "object-row-table", data };
85
85
  }
86
86
  };
87
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["index.js", "excel-loader.js", "lib/parse-excel.js"],
4
+ "sourcesContent": ["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nimport { ExcelLoader as ExcelWorkerLoader } from \"./excel-loader.js\";\nimport { parseExcel } from \"./lib/parse-excel.js\";\nexport { ExcelWorkerLoader };\n/**\n * Loader for Excel files\n */\nexport const ExcelLoader = {\n ...ExcelWorkerLoader,\n async parse(arrayBuffer, options) {\n const data = parseExcel(arrayBuffer, options);\n return { shape: 'object-row-table', data };\n }\n};\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof \"4.2.0-alpha.4\" !== 'undefined' ? \"4.2.0-alpha.4\" : 'latest';\nconst DEFAULT_EXCEL_LOADER_OPTIONS = {\n excel: {\n shape: 'object-row-table',\n sheet: undefined // Load default Sheet\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", "import { utils, read } from 'xlsx';\n// import {convertToArrayRow} from '@loaders.gl/schema';\n// local table names cache with dataUrl/tableNames array key/values\nconst dataTableNamesMap = {};\n/**\n * Gets local or remote Excel file data.\n * @param arrayBuffer Loaded data\n * @param options Data parse options.\n */\nexport function parseExcel(arrayBuffer, options) {\n const dataUrl = 'dummy';\n // const dataFileType: string = dataUrl.substr(dataUrl.lastIndexOf('.')); // file extension\n // create Excel 'workbook'\n const workbook = read(arrayBuffer, {\n type: 'array'\n // cellDates: true\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 // 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 // get worksheet data row objects array\n const worksheet = workbook.Sheets[sheetName];\n dataRows = utils.sheet_to_json(worksheet);\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 return dataRows;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,qBAAAA;AAAA,EAAA;AAAA;AAAA;;;ACKA,IAAM,UAAU,OAAyC,kBAAkB;AAC3E,IAAM,+BAA+B;AAAA,EACjC,OAAO;AAAA,IACH,OAAO;AAAA,IACP,OAAO;AAAA;AAAA,EACX;AACJ;AAIO,IAAM,cAAc;AAAA,EACvB,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,YAAY,CAAC,OAAO,QAAQ,QAAQ,MAAM;AAAA,EAC1C,WAAW;AAAA,IACP;AAAA,IACA;AAAA,EACJ;AAAA,EACA,UAAU;AAAA,EACV,QAAQ;AAAA,EACR,SAAS;AACb;;;AC7BA,kBAA4B;AAG5B,IAAM,oBAAoB,CAAC;AAMpB,SAAS,WAAW,aAAa,SAAS;AATjD;AAUI,QAAM,UAAU;AAGhB,QAAM,eAAW,kBAAK,aAAa;AAAA,IAC/B,MAAM;AAAA;AAAA,EAEV,CAAC;AAED,MAAI,WAAW,CAAC;AAChB,oBAAkB,OAAO,IAAI,CAAC;AAC9B,MAAI,SAAS,WAAW,SAAS,GAAG;AAChC,QAAI,SAAS,WAAW,SAAS,GAAG;AAEhC,wBAAkB,OAAO,IAAI,SAAS;AAAA,IAG1C;AAEA,QAAI,YAAY,SAAS,WAAW,CAAC;AACrC,UAAI,wCAAS,UAAT,mBAAgB,UAAS,SAAS,WAAW,SAAQ,wCAAS,UAAT,mBAAgB,KAAK,KAAK,GAAG;AAElF,mBAAY,wCAAS,UAAT,mBAAgB;AAAA,IAChC;AAEA,UAAM,YAAY,SAAS,OAAO,SAAS;AAC3C,eAAW,kBAAM,cAAc,SAAS;AAAA,EAK5C;AACA,SAAO;AACX;;;AFjCO,IAAMC,eAAc;AAAA,EACvB,GAAG;AAAA,EACH,MAAM,MAAM,aAAa,SAAS;AAC9B,UAAM,OAAO,WAAW,aAAa,OAAO;AAC5C,WAAO,EAAE,OAAO,oBAAoB,KAAK;AAAA,EAC7C;AACJ;",
6
+ "names": ["ExcelLoader", "ExcelLoader"]
7
+ }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { LoaderWithParser } from '@loaders.gl/loader-utils';
2
2
  import type { ObjectRowTable } from '@loaders.gl/schema';
3
- import type { ExcelLoaderOptions } from './excel-loader';
4
- import { ExcelLoader as ExcelWorkerLoader } from './excel-loader';
3
+ import type { ExcelLoaderOptions } from "./excel-loader.js";
4
+ import { ExcelLoader as ExcelWorkerLoader } from "./excel-loader.js";
5
5
  export type { ExcelLoaderOptions };
6
6
  export { ExcelWorkerLoader };
7
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAC,kBAAkB,EAAC,0BAAuB;AACvD,OAAO,EAAC,WAAW,IAAI,iBAAiB,EAAC,0BAAuB;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,14 +1,16 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  import { ExcelLoader as ExcelWorkerLoader } from "./excel-loader.js";
2
5
  import { parseExcel } from "./lib/parse-excel.js";
3
6
  export { ExcelWorkerLoader };
7
+ /**
8
+ * Loader for Excel files
9
+ */
4
10
  export const ExcelLoader = {
5
- ...ExcelWorkerLoader,
6
- async parse(arrayBuffer, options) {
7
- const data = parseExcel(arrayBuffer, options);
8
- return {
9
- shape: 'object-row-table',
10
- data
11
- };
12
- }
11
+ ...ExcelWorkerLoader,
12
+ async parse(arrayBuffer, options) {
13
+ const data = parseExcel(arrayBuffer, options);
14
+ return { shape: 'object-row-table', data };
15
+ }
13
16
  };
14
- //# sourceMappingURL=index.js.map
@@ -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
- //# sourceMappingURL=encode-excel.js.map
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
+ */
@@ -1,4 +1,4 @@
1
- import type { ExcelLoaderOptions } from '../excel-loader';
1
+ import type { ExcelLoaderOptions } from "../excel-loader.js";
2
2
  /**
3
3
  * Gets local or remote Excel file data.
4
4
  * @param arrayBuffer Loaded data
@@ -1 +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"}
1
+ {"version":3,"file":"parse-excel.d.ts","sourceRoot":"","sources":["../../src/lib/parse-excel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,kBAAkB,EAAC,2BAAwB;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"}
@@ -1,25 +1,43 @@
1
1
  import { utils, read } from 'xlsx';
2
+ // import {convertToArrayRow} from '@loaders.gl/schema';
3
+ // local table names cache with dataUrl/tableNames array key/values
2
4
  const dataTableNamesMap = {};
5
+ /**
6
+ * Gets local or remote Excel file data.
7
+ * @param arrayBuffer Loaded data
8
+ * @param options Data parse options.
9
+ */
3
10
  export function parseExcel(arrayBuffer, options) {
4
- const dataUrl = 'dummy';
5
- const workbook = read(arrayBuffer, {
6
- type: 'array'
7
- });
8
- let dataRows = [];
9
- dataTableNamesMap[dataUrl] = [];
10
- if (workbook.SheetNames.length > 0) {
11
- var _options$excel, _options$excel2;
12
- if (workbook.SheetNames.length > 1) {
13
- dataTableNamesMap[dataUrl] = workbook.SheetNames;
11
+ const dataUrl = 'dummy';
12
+ // const dataFileType: string = dataUrl.substr(dataUrl.lastIndexOf('.')); // file extension
13
+ // create Excel 'workbook'
14
+ const workbook = read(arrayBuffer, {
15
+ type: 'array'
16
+ // cellDates: true
17
+ });
18
+ // load data sheets
19
+ let dataRows = [];
20
+ dataTableNamesMap[dataUrl] = [];
21
+ if (workbook.SheetNames.length > 0) {
22
+ if (workbook.SheetNames.length > 1) {
23
+ // cache sheet names
24
+ dataTableNamesMap[dataUrl] = workbook.SheetNames;
25
+ // eslint-ignore-next-line
26
+ // console.debug(`getData(): file: sheetNames:`, workbook.SheetNames);
27
+ }
28
+ // determine spreadsheet to load
29
+ let sheetName = workbook.SheetNames[0];
30
+ if (options?.excel?.sheet && workbook.SheetNames.indexOf(options?.excel?.sheet) >= 0) {
31
+ // reset to requested table name
32
+ sheetName = options?.excel?.sheet;
33
+ }
34
+ // get worksheet data row objects array
35
+ const worksheet = workbook.Sheets[sheetName];
36
+ dataRows = utils.sheet_to_json(worksheet);
37
+ // const headers = dataRows.length ? Object.keys(dataRows[0]) : [];
38
+ // if (options?.excel?.type === 'array-row-table') {
39
+ // dataRows = dataRows.map(row => convertToArrayRow(row, headers))
40
+ // }
14
41
  }
15
- let sheetName = workbook.SheetNames[0];
16
- 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) {
17
- var _options$excel3;
18
- sheetName = options === null || options === void 0 ? void 0 : (_options$excel3 = options.excel) === null || _options$excel3 === void 0 ? void 0 : _options$excel3.sheet;
19
- }
20
- const worksheet = workbook.Sheets[sheetName];
21
- dataRows = utils.sheet_to_json(worksheet);
22
- }
23
- return dataRows;
42
+ return dataRows;
24
43
  }
25
- //# sourceMappingURL=parse-excel.js.map
@@ -1,4 +1,3 @@
1
1
  import { createLoaderWorker } from '@loaders.gl/loader-utils';
2
2
  import { ExcelLoader } from "../index.js";
3
3
  createLoaderWorker(ExcelLoader);
4
- //# sourceMappingURL=excel-worker.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/excel",
3
- "version": "4.2.0-alpha.4",
3
+ "version": "4.2.0-alpha.5",
4
4
  "description": "Framework-independent loader for Excel files",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -38,14 +38,18 @@
38
38
  "README.md"
39
39
  ],
40
40
  "scripts": {
41
- "pre-build": "npm run build-bundle && npm run build-bundle -- --env=dev && npm run build-worker",
42
- "build-bundle": "ocular-bundle ./src/index.ts",
41
+ "pre-build": "npm run build-bundle && npm run build-bundle-dev && npm run build-worker",
42
+ "build-bundle": "ocular-bundle ./bundle.ts --output=dist/dist.min.js",
43
+ "build-bundle-dev": "ocular-bundle ./bundle.ts --env=dev --output=dist/dist.dev.js",
43
44
  "build-worker": "esbuild src/workers/excel-worker.ts --bundle --outfile=dist/excel-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
44
45
  },
45
46
  "dependencies": {
46
- "@loaders.gl/loader-utils": "4.2.0-alpha.4",
47
- "@loaders.gl/schema": "4.2.0-alpha.4",
47
+ "@loaders.gl/loader-utils": "4.2.0-alpha.5",
48
+ "@loaders.gl/schema": "4.2.0-alpha.5",
48
49
  "xlsx": "^0.18.5"
49
50
  },
50
- "gitHead": "6c52dee5c3f005648a394cc4aee7fc37005c8e83"
51
+ "peerDependencies": {
52
+ "@loaders.gl/core": "^4.0.0"
53
+ },
54
+ "gitHead": "32d95a81971f104e4dfeb88ab57065f05321a76a"
51
55
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"excel-loader.js","names":["VERSION","DEFAULT_EXCEL_LOADER_OPTIONS","excel","shape","sheet","undefined","ExcelLoader","name","id","module","version","worker","extensions","mimeTypes","category","binary","options"],"sources":["../src/excel-loader.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {ObjectRowTable} from '@loaders.gl/schema';\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: Loader<ObjectRowTable, never, ExcelLoaderOptions> = {\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"],"mappings":"AASA,MAAMA,OAAO,GAAG,sBAAkB,KAAK,WAAW,qBAAiB,QAAQ;AAS3E,MAAMC,4BAAgD,GAAG;EACvDC,KAAK,EAAE;IACLC,KAAK,EAAE,kBAAkB;IACzBC,KAAK,EAAEC;EACT;AACF,CAAC;AAKD,OAAO,MAAMC,WAA8D,GAAG;EAC5EC,IAAI,EAAE,OAAO;EACbC,EAAE,EAAE,OAAO;EACXC,MAAM,EAAE,OAAO;EACfC,OAAO,EAAEV,OAAO;EAChBW,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;EAC3CC,SAAS,EAAE,CACT,mEAAmE,EACnE,0BAA0B,CAC3B;EACDC,QAAQ,EAAE,OAAO;EACjBC,MAAM,EAAE,IAAI;EACZC,OAAO,EAAEf;AACX,CAAC"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["ExcelLoader","ExcelWorkerLoader","parseExcel","parse","arrayBuffer","options","data","shape"],"sources":["../src/index.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {ObjectRowTable} from '@loaders.gl/schema';\nimport type {ExcelLoaderOptions} from './excel-loader';\nimport {ExcelLoader as ExcelWorkerLoader} 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: LoaderWithParser<ObjectRowTable, never, ExcelLoaderOptions> = {\n ...ExcelWorkerLoader,\n async parse(arrayBuffer: ArrayBuffer, options?: ExcelLoaderOptions): Promise<ObjectRowTable> {\n const data = parseExcel(arrayBuffer, options);\n return {shape: 'object-row-table', data};\n }\n};\n"],"mappings":"SAOQA,WAAW,IAAIC,iBAAiB;AAAA,SAChCC,UAAU;AAKlB,SAAQD,iBAAiB;AAKzB,OAAO,MAAMD,WAAwE,GAAG;EACtF,GAAGC,iBAAiB;EACpB,MAAME,KAAKA,CAACC,WAAwB,EAAEC,OAA4B,EAA2B;IAC3F,MAAMC,IAAI,GAAGJ,UAAU,CAACE,WAAW,EAAEC,OAAO,CAAC;IAC7C,OAAO;MAACE,KAAK,EAAE,kBAAkB;MAAED;IAAI,CAAC;EAC1C;AACF,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"encode-excel.js","names":[],"sources":["../../src/lib/encode-excel.ts"],"sourcesContent":["// import * as xlsx from 'xlsx';\n\n/**\n * Saves JSON data in Excel format for html, ods, xml, xlsb and xlsx file types.\n * @param filePath Local data file path.\n * @param fileData Raw data to save.\n * @param tableName Table name for data files with multiple tables support.\n * @param showData Show saved data callback.\n *\n public saveData(filePath: string, fileData: any, tableName: string, showData?: Function): void {\n const fileType: string = filePath.substr(filePath.lastIndexOf('.'));\n fileData = this.jsonToExcelData(fileData, fileType, tableName);\n if ( fileData.length > 0) {\n // TODO: change this to async later\n fs.writeFile(filePath, fileData, (error) => showData(error));\n }\n }\n\n /**\n * Converts JSON data to Excel data formats.\n * @param jsonData Json data to convert.\n * @param bookType Excel data file/book type.\n *\n private jsonToExcelData(jsonData: any, fileType: string, tableName: string): any {\n console.debug('jsonToExcelData(): creating excel data:', fileType);\n\n // create new workbook\n const workbook = xlsx.utils.book_new();\n\n // convert json data to worksheet format\n const worksheet = xlsx.utils.json_to_sheet(jsonData, {\n //header: JSON.parse(this._viewConfig.columns)\n });\n\n // append worksheet to workbook\n xlsx.utils.book_append_sheet(workbook, worksheet, tableName);\n\n // get text data string or binary spreadsheet data buffer\n let data: any = '';\n if (fileType === 'html' || fileType === 'xml') {\n data = xlsx.write(workbook, {\n type: 'string',\n compression: false,\n bookType: getBookType(fileType)\n });\n } else {\n data = xlsx.write(workbook, {\n type: 'buffer',\n compression: true, // use zip compression for zip-based formats\n bookType: getBookType(fileType)\n });\n }\n return data;\n }\n\n\n}\n\n/**\n * Converts file type to Excel book type.\n * @param {string} fileType File type: .html, .ods, .xml, .xlsb, .xlsx, etc.\n * @returns {xlsx.BookType}\n *\nfunction getBookType(fileType) {\n // TODO: must be a better way to do this string to type conversion :)\n switch (fileType) {\n case '.html':\n return 'html';\n case '.ods':\n return 'ods';\n case '.xml':\n return 'xlml';\n case '.xlsb':\n return 'xlsb';\n case '.xlsx':\n return 'xlsx';\n default:\n return 'xlsb';\n }\n}\n*/\n"],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse-excel.js","names":["utils","read","dataTableNamesMap","parseExcel","arrayBuffer","options","dataUrl","workbook","type","dataRows","SheetNames","length","_options$excel","_options$excel2","sheetName","excel","sheet","indexOf","_options$excel3","worksheet","Sheets","sheet_to_json"],"sources":["../../src/lib/parse-excel.ts"],"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 function parseExcel(\n arrayBuffer: ArrayBuffer,\n options?: ExcelLoaderOptions\n): {[key: string]: unknown}[] {\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: {[key: string]: unknown}[] = [];\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"],"mappings":"AACA,SAAQA,KAAK,EAAEC,IAAI,QAAO,MAAM;AAIhC,MAAMC,iBAAiB,GAAG,CAAC,CAAC;AAO5B,OAAO,SAASC,UAAUA,CACxBC,WAAwB,EACxBC,OAA4B,EACA;EAC5B,MAAMC,OAAO,GAAG,OAAO;EAIvB,MAAMC,QAAQ,GAAGN,IAAI,CAACG,WAAW,EAAE;IACjCI,IAAI,EAAE;EAER,CAAC,CAAC;EAGF,IAAIC,QAAoC,GAAG,EAAE;EAC7CP,iBAAiB,CAACI,OAAO,CAAC,GAAG,EAAE;EAC/B,IAAIC,QAAQ,CAACG,UAAU,CAACC,MAAM,GAAG,CAAC,EAAE;IAAA,IAAAC,cAAA,EAAAC,eAAA;IAClC,IAAIN,QAAQ,CAACG,UAAU,CAACC,MAAM,GAAG,CAAC,EAAE;MAElCT,iBAAiB,CAACI,OAAO,CAAC,GAAGC,QAAQ,CAACG,UAAU;IAGlD;IAGA,IAAII,SAAS,GAAGP,QAAQ,CAACG,UAAU,CAAC,CAAC,CAAC;IACtC,IAAIL,OAAO,aAAPA,OAAO,gBAAAO,cAAA,GAAPP,OAAO,CAAEU,KAAK,cAAAH,cAAA,eAAdA,cAAA,CAAgBI,KAAK,IAAIT,QAAQ,CAACG,UAAU,CAACO,OAAO,CAACZ,OAAO,aAAPA,OAAO,wBAAAQ,eAAA,GAAPR,OAAO,CAAEU,KAAK,cAAAF,eAAA,uBAAdA,eAAA,CAAgBG,KAAK,CAAC,IAAI,CAAC,EAAE;MAAA,IAAAE,eAAA;MAEpFJ,SAAS,GAAGT,OAAO,aAAPA,OAAO,wBAAAa,eAAA,GAAPb,OAAO,CAAEU,KAAK,cAAAG,eAAA,uBAAdA,eAAA,CAAgBF,KAAK;IACnC;IAGA,MAAMG,SAAS,GAAGZ,QAAQ,CAACa,MAAM,CAACN,SAAS,CAAC;IAC5CL,QAAQ,GAAGT,KAAK,CAACqB,aAAa,CAACF,SAAS,CAAC;EAM3C;EAEA,OAAOV,QAAQ;AACjB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"excel-worker.js","names":["createLoaderWorker","ExcelLoader"],"sources":["../../src/workers/excel-worker.ts"],"sourcesContent":["import {createLoaderWorker} from '@loaders.gl/loader-utils';\nimport {ExcelLoader} from '../index';\n\ncreateLoaderWorker(ExcelLoader);\n"],"mappings":"AAAA,SAAQA,kBAAkB,QAAO,0BAA0B;AAAC,SACpDC,WAAW;AAEnBD,kBAAkB,CAACC,WAAW,CAAC"}