read-excel-file 9.3.3 → 9.3.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/CHANGELOG.md +9 -0
- package/README.md +32 -2
- package/browser/index.cjs +3 -0
- package/browser/index.d.ts +16 -0
- package/browser/index.js +4 -1
- package/bundle/read-excel-file.min.js +1 -1
- package/bundle/read-excel-file.min.js.map +1 -1
- package/commonjs/export/convertInputToNodeStream.js +0 -12
- package/commonjs/export/convertInputToNodeStream.js.map +1 -1
- package/commonjs/export/parseSheet.js +14 -7
- package/commonjs/export/parseSheet.js.map +1 -1
- package/commonjs/export/readSheetBrowser.js +3 -6
- package/commonjs/export/readSheetBrowser.js.map +1 -1
- package/commonjs/export/readSheetNode.js +3 -6
- package/commonjs/export/readSheetNode.js.map +1 -1
- package/commonjs/export/readSheetUniversal.js +2 -2
- package/commonjs/export/readSheetUniversal.js.map +1 -1
- package/commonjs/export/readSheetWebWorker.js +5 -5
- package/commonjs/export/readSheetWebWorker.js.map +1 -1
- package/commonjs/export/readXlsxFileBrowser.js +3 -6
- package/commonjs/export/readXlsxFileBrowser.js.map +1 -1
- package/commonjs/export/readXlsxFileNode.js +3 -6
- package/commonjs/export/readXlsxFileNode.js.map +1 -1
- package/commonjs/export/readXlsxFileUniversal.js +2 -2
- package/commonjs/export/readXlsxFileUniversal.js.map +1 -1
- package/commonjs/export/readXlsxFileWebWorker.js +5 -5
- package/commonjs/export/readXlsxFileWebWorker.js.map +1 -1
- package/commonjs/export/unpackXlsxFileBrowser.js +15 -4
- package/commonjs/export/unpackXlsxFileBrowser.js.map +1 -1
- package/commonjs/export/unpackXlsxFileBrowser.test.js.map +1 -0
- package/commonjs/export/unpackXlsxFileNode.js +32 -5
- package/commonjs/export/unpackXlsxFileNode.js.map +1 -1
- package/commonjs/export/unpackXlsxFileNode.test.js.map +1 -0
- package/commonjs/export/unpackXlsxFileUniversal.js +14 -3
- package/commonjs/export/unpackXlsxFileUniversal.js.map +1 -1
- package/commonjs/export/unpackXlsxFileUniversal.test.js.map +1 -0
- package/commonjs/parseSheetData/parseSheetData.js +9 -6
- package/commonjs/parseSheetData/parseSheetData.js.map +1 -1
- package/commonjs/saxen/parser.js +1 -1
- package/commonjs/saxen/parser.js.map +1 -1
- package/commonjs/utility/convertValuesFromUint8ArraysToStrings.js +100 -0
- package/commonjs/utility/convertValuesFromUint8ArraysToStrings.js.map +1 -0
- package/commonjs/xlsx/InvalidSpreadsheetError.js +55 -0
- package/commonjs/xlsx/InvalidSpreadsheetError.js.map +1 -0
- package/commonjs/xlsx/SheetNotFoundError.js +55 -0
- package/commonjs/xlsx/SheetNotFoundError.js.map +1 -0
- package/commonjs/xlsx/file/InputValidationStream.js +101 -0
- package/commonjs/xlsx/file/InputValidationStream.js.map +1 -0
- package/commonjs/xlsx/file/InputValidationStream.test.js.map +1 -0
- package/commonjs/xlsx/file/InvalidInputError.js +105 -0
- package/commonjs/xlsx/file/InvalidInputError.js.map +1 -0
- package/commonjs/xlsx/file/createFileTypeDetector.js +70 -0
- package/commonjs/xlsx/file/createFileTypeDetector.js.map +1 -0
- package/commonjs/xlsx/file/createFileTypeDetector.test.js.map +1 -0
- package/commonjs/xlsx/file/validateLeadingBytes.js +47 -0
- package/commonjs/xlsx/file/validateLeadingBytes.js.map +1 -0
- package/commonjs/xlsx/file/validateLeadingBytes.test.js.map +1 -0
- package/commonjs/xlsx/isDateFormat.js +32 -27
- package/commonjs/xlsx/isDateFormat.js.map +1 -1
- package/commonjs/xlsx/isDateFormatStyle.js +19 -21
- package/commonjs/xlsx/isDateFormatStyle.js.map +1 -1
- package/commonjs/xlsx/parseCell.js +252 -115
- package/commonjs/xlsx/parseCell.js.map +1 -1
- package/commonjs/xlsx/parseCellAddress.js +22 -18
- package/commonjs/xlsx/parseCellAddress.js.map +1 -1
- package/commonjs/xlsx/parseExcelDate.js +4 -124
- package/commonjs/xlsx/parseExcelDate.js.map +1 -1
- package/commonjs/xlsx/parseExcelDate.test.js.map +1 -1
- package/commonjs/xlsx/parseExcelTimestamp.js +139 -0
- package/commonjs/xlsx/parseExcelTimestamp.js.map +1 -0
- package/commonjs/xlsx/parseFilePaths.js +48 -47
- package/commonjs/xlsx/parseFilePaths.js.map +1 -1
- package/commonjs/xlsx/parseSharedStrings.js +91 -36
- package/commonjs/xlsx/parseSharedStrings.js.map +1 -1
- package/commonjs/xlsx/parseSheet.js +527 -69
- package/commonjs/xlsx/parseSheet.js.map +1 -1
- package/commonjs/xlsx/parseSpreadsheetContents.js +154 -83
- package/commonjs/xlsx/parseSpreadsheetContents.js.map +1 -1
- package/commonjs/xlsx/parseSpreadsheetInfo.js +60 -59
- package/commonjs/xlsx/parseSpreadsheetInfo.js.map +1 -1
- package/commonjs/xlsx/parseStyles.js +75 -75
- package/commonjs/xlsx/parseStyles.js.map +1 -1
- package/commonjs/xml/parseXml.js +112 -0
- package/commonjs/xml/parseXml.js.map +1 -0
- package/commonjs/xml/parseXml.test.js.map +1 -0
- package/commonjs/xml/parseXmlStream.js.map +1 -1
- package/commonjs/xml/parseXmlStream.sax.js +69 -28
- package/commonjs/xml/parseXmlStream.sax.js.map +1 -1
- package/commonjs/xml/parseXmlStream.saxen.js +66 -40
- package/commonjs/xml/parseXmlStream.saxen.js.map +1 -1
- package/commonjs/zip/UnzipError.js +55 -0
- package/commonjs/zip/UnzipError.js.map +1 -0
- package/commonjs/zip/unzipFromArrayBuffer.js +21 -1
- package/commonjs/zip/unzipFromArrayBuffer.js.map +1 -1
- package/commonjs/zip/unzipFromArrayBuffer.test.js.map +1 -0
- package/commonjs/zip/unzipFromStream.fflate.js +43 -35
- package/commonjs/zip/unzipFromStream.fflate.js.map +1 -1
- package/commonjs/zip/unzipFromStream.js +188 -6
- package/commonjs/zip/unzipFromStream.js.map +1 -1
- package/commonjs/zip/unzipFromStream.unzipper.js +19 -34
- package/commonjs/zip/unzipFromStream.unzipper.js.map +1 -1
- package/modules/export/convertInputToNodeStream.js +0 -12
- package/modules/export/convertInputToNodeStream.js.map +1 -1
- package/modules/export/parseSheet.js +13 -6
- package/modules/export/parseSheet.js.map +1 -1
- package/modules/export/readSheetBrowser.js +3 -5
- package/modules/export/readSheetBrowser.js.map +1 -1
- package/modules/export/readSheetNode.js +3 -5
- package/modules/export/readSheetNode.js.map +1 -1
- package/modules/export/readSheetUniversal.js +2 -2
- package/modules/export/readSheetUniversal.js.map +1 -1
- package/modules/export/readSheetWebWorker.js +7 -8
- package/modules/export/readSheetWebWorker.js.map +1 -1
- package/modules/export/readXlsxFileBrowser.js +3 -5
- package/modules/export/readXlsxFileBrowser.js.map +1 -1
- package/modules/export/readXlsxFileNode.js +3 -5
- package/modules/export/readXlsxFileNode.js.map +1 -1
- package/modules/export/readXlsxFileUniversal.js +2 -2
- package/modules/export/readXlsxFileUniversal.js.map +1 -1
- package/modules/export/readXlsxFileWebWorker.js +7 -8
- package/modules/export/readXlsxFileWebWorker.js.map +1 -1
- package/modules/export/unpackXlsxFileBrowser.js +15 -4
- package/modules/export/unpackXlsxFileBrowser.js.map +1 -1
- package/modules/export/unpackXlsxFileBrowser.test.js.map +1 -0
- package/modules/export/unpackXlsxFileNode.js +32 -5
- package/modules/export/unpackXlsxFileNode.js.map +1 -1
- package/modules/export/unpackXlsxFileNode.test.js.map +1 -0
- package/modules/export/unpackXlsxFileUniversal.js +14 -3
- package/modules/export/unpackXlsxFileUniversal.js.map +1 -1
- package/modules/export/unpackXlsxFileUniversal.test.js.map +1 -0
- package/modules/parseSheetData/parseSheetData.js +9 -6
- package/modules/parseSheetData/parseSheetData.js.map +1 -1
- package/modules/saxen/parser.js +1 -1
- package/modules/saxen/parser.js.map +1 -1
- package/modules/utility/convertValuesFromUint8ArraysToStrings.js +92 -0
- package/modules/utility/convertValuesFromUint8ArraysToStrings.js.map +1 -0
- package/modules/xlsx/InvalidSpreadsheetError.js +50 -0
- package/modules/xlsx/InvalidSpreadsheetError.js.map +1 -0
- package/modules/xlsx/SheetNotFoundError.js +50 -0
- package/modules/xlsx/SheetNotFoundError.js.map +1 -0
- package/modules/xlsx/file/InputValidationStream.js +96 -0
- package/modules/xlsx/file/InputValidationStream.js.map +1 -0
- package/modules/xlsx/file/InputValidationStream.test.js.map +1 -0
- package/modules/xlsx/file/InvalidInputError.js +100 -0
- package/modules/xlsx/file/InvalidInputError.js.map +1 -0
- package/modules/xlsx/file/createFileTypeDetector.js +63 -0
- package/modules/xlsx/file/createFileTypeDetector.js.map +1 -0
- package/modules/xlsx/file/createFileTypeDetector.test.js.map +1 -0
- package/modules/xlsx/file/validateLeadingBytes.js +37 -0
- package/modules/xlsx/file/validateLeadingBytes.js.map +1 -0
- package/modules/xlsx/file/validateLeadingBytes.test.js.map +1 -0
- package/modules/xlsx/isDateFormat.js +31 -27
- package/modules/xlsx/isDateFormat.js.map +1 -1
- package/modules/xlsx/isDateFormatStyle.js +18 -21
- package/modules/xlsx/isDateFormatStyle.js.map +1 -1
- package/modules/xlsx/parseCell.js +251 -111
- package/modules/xlsx/parseCell.js.map +1 -1
- package/modules/xlsx/parseCellAddress.js +21 -18
- package/modules/xlsx/parseCellAddress.js.map +1 -1
- package/modules/xlsx/parseExcelDate.js +4 -124
- package/modules/xlsx/parseExcelDate.js.map +1 -1
- package/modules/xlsx/parseExcelDate.test.js.map +1 -1
- package/modules/xlsx/parseExcelTimestamp.js +133 -0
- package/modules/xlsx/parseExcelTimestamp.js.map +1 -0
- package/modules/xlsx/parseFilePaths.js +48 -47
- package/modules/xlsx/parseFilePaths.js.map +1 -1
- package/modules/xlsx/parseSharedStrings.js +91 -37
- package/modules/xlsx/parseSharedStrings.js.map +1 -1
- package/modules/xlsx/parseSheet.js +526 -68
- package/modules/xlsx/parseSheet.js.map +1 -1
- package/modules/xlsx/parseSpreadsheetContents.js +153 -81
- package/modules/xlsx/parseSpreadsheetContents.js.map +1 -1
- package/modules/xlsx/parseSpreadsheetInfo.js +60 -59
- package/modules/xlsx/parseSpreadsheetInfo.js.map +1 -1
- package/modules/xlsx/parseStyles.js +75 -75
- package/modules/xlsx/parseStyles.js.map +1 -1
- package/modules/xml/parseXml.js +106 -0
- package/modules/xml/parseXml.js.map +1 -0
- package/modules/xml/parseXml.test.js.map +1 -0
- package/modules/xml/parseXmlStream.js +2 -0
- package/modules/xml/parseXmlStream.js.map +1 -1
- package/modules/xml/parseXmlStream.sax.js +69 -28
- package/modules/xml/parseXmlStream.sax.js.map +1 -1
- package/modules/xml/parseXmlStream.saxen.js +67 -40
- package/modules/xml/parseXmlStream.saxen.js.map +1 -1
- package/modules/zip/UnzipError.js +49 -0
- package/modules/zip/UnzipError.js.map +1 -0
- package/modules/zip/unzipFromArrayBuffer.js +21 -1
- package/modules/zip/unzipFromArrayBuffer.js.map +1 -1
- package/modules/zip/unzipFromArrayBuffer.test.js.map +1 -0
- package/modules/zip/unzipFromStream.fflate.js +41 -35
- package/modules/zip/unzipFromStream.fflate.js.map +1 -1
- package/modules/zip/unzipFromStream.js +124 -1
- package/modules/zip/unzipFromStream.js.map +1 -1
- package/modules/zip/unzipFromStream.unzipper.js +19 -35
- package/modules/zip/unzipFromStream.unzipper.js.map +1 -1
- package/node/index.cjs +3 -0
- package/node/index.d.ts +16 -0
- package/node/index.js +3 -0
- package/package.json +5 -3
- package/types/InvalidInputError.d.ts +16 -0
- package/types/InvalidSpreadsheetError.d.ts +4 -0
- package/types/SheetNotFoundError.d.ts +4 -0
- package/universal/index.cjs +3 -0
- package/universal/index.d.ts +16 -0
- package/universal/index.js +3 -0
- package/web-worker/index.cjs +3 -0
- package/web-worker/index.d.ts +16 -0
- package/web-worker/index.js +3 -0
- package/commonjs/export/convertValuesFromUint8ArraysToStrings.js +0 -23
- package/commonjs/export/convertValuesFromUint8ArraysToStrings.js.map +0 -1
- package/commonjs/xlsx/convertCellsToData2dArray.js +0 -84
- package/commonjs/xlsx/convertCellsToData2dArray.js.map +0 -1
- package/commonjs/xlsx/dropEmptyColumns.js +0 -40
- package/commonjs/xlsx/dropEmptyColumns.js.map +0 -1
- package/commonjs/xlsx/dropEmptyColumns.test.js.map +0 -1
- package/commonjs/xlsx/dropEmptyRows.js +0 -43
- package/commonjs/xlsx/dropEmptyRows.js.map +0 -1
- package/commonjs/xlsx/dropEmptyRows.test.js.map +0 -1
- package/commonjs/xlsx/parseCellValue.js +0 -186
- package/commonjs/xlsx/parseCellValue.js.map +0 -1
- package/commonjs/xlsx/parseNumber.js +0 -20
- package/commonjs/xlsx/parseNumber.js.map +0 -1
- package/commonjs/xlsx/parseSharedString.js +0 -64
- package/commonjs/xlsx/parseSharedString.js.map +0 -1
- package/commonjs/xlsx/parseSheetData.js +0 -68
- package/commonjs/xlsx/parseSheetData.js.map +0 -1
- package/commonjs/xlsx/reconstructSheetDimensionsFromSheetCells.js +0 -29
- package/commonjs/xlsx/reconstructSheetDimensionsFromSheetCells.js.map +0 -1
- package/commonjs/xml/parseXmlStream.saxen.code.js +0 -953
- package/commonjs/xml/parseXmlStream.saxen.code.js.map +0 -1
- package/commonjs/xml/parseXmlStream.test.js.map +0 -1
- package/modules/export/convertValuesFromUint8ArraysToStrings.js +0 -17
- package/modules/export/convertValuesFromUint8ArraysToStrings.js.map +0 -1
- package/modules/xlsx/convertCellsToData2dArray.js +0 -77
- package/modules/xlsx/convertCellsToData2dArray.js.map +0 -1
- package/modules/xlsx/dropEmptyColumns.js +0 -34
- package/modules/xlsx/dropEmptyColumns.js.map +0 -1
- package/modules/xlsx/dropEmptyColumns.test.js.map +0 -1
- package/modules/xlsx/dropEmptyRows.js +0 -37
- package/modules/xlsx/dropEmptyRows.js.map +0 -1
- package/modules/xlsx/dropEmptyRows.test.js.map +0 -1
- package/modules/xlsx/parseCellValue.js +0 -180
- package/modules/xlsx/parseCellValue.js.map +0 -1
- package/modules/xlsx/parseNumber.js +0 -14
- package/modules/xlsx/parseNumber.js.map +0 -1
- package/modules/xlsx/parseSharedString.js +0 -55
- package/modules/xlsx/parseSharedString.js.map +0 -1
- package/modules/xlsx/parseSheetData.js +0 -55
- package/modules/xlsx/parseSheetData.js.map +0 -1
- package/modules/xlsx/reconstructSheetDimensionsFromSheetCells.js +0 -23
- package/modules/xlsx/reconstructSheetDimensionsFromSheetCells.js.map +0 -1
- package/modules/xml/parseXmlStream.saxen.code.js +0 -947
- package/modules/xml/parseXmlStream.saxen.code.js.map +0 -1
- package/modules/xml/parseXmlStream.test.js.map +0 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = convertValuesFromUint8ArraysToStrings;
|
|
7
|
+
exports.strFromU8 = strFromU8;
|
|
8
|
+
var _fflate = require("fflate");
|
|
9
|
+
var _checkpoint = _interopRequireDefault(require("./checkpoint.js"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
// Sidenote: `strFromU8()` function from `fflate` is not "self-contained",
|
|
12
|
+
// i.e. it references some variables outside of its scope,
|
|
13
|
+
// which doesn't work with `worker-f` package and throws an error: "td is not defined".
|
|
14
|
+
//
|
|
15
|
+
// But `woker-f` package is currently not used, so this `import` is not commented out.
|
|
16
|
+
//
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {Record<string,Uint8Array} entries
|
|
20
|
+
* @returns {Record<string,string>}
|
|
21
|
+
*/
|
|
22
|
+
function convertValuesFromUint8ArraysToStrings(entries) {
|
|
23
|
+
(0, _checkpoint["default"])('convert files to strings');
|
|
24
|
+
var convertedEntries = {};
|
|
25
|
+
for (var _i = 0, _Object$keys = Object.keys(entries); _i < _Object$keys.length; _i++) {
|
|
26
|
+
var key = _Object$keys[_i];
|
|
27
|
+
convertedEntries[key] = strFromU8(entries[key]);
|
|
28
|
+
}
|
|
29
|
+
return convertedEntries;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// There's a strange thing with using `fflate`'s `strFromU8()` function:
|
|
33
|
+
// when `import`ed directly from `fflate` package, the benchmark runs about 10% slower
|
|
34
|
+
// then when using `new TextDecoder().decode(data)`, even though `strFromU8()`
|
|
35
|
+
// does the same thing internally. So it's a bit mysterious.
|
|
36
|
+
//
|
|
37
|
+
// Because manually calling `new TextDecoder().decode(data)` is measurably faster for some reason,
|
|
38
|
+
// `fflate`'s `strFromU8()` is used as a backup for old web browsers that don't support `TextDecoder`.
|
|
39
|
+
//
|
|
40
|
+
/**
|
|
41
|
+
* Converts a Uint8Array to a string
|
|
42
|
+
* @param data The data to decode to string
|
|
43
|
+
* @param latin1 Whether or not to interpret the data as Latin-1. This should
|
|
44
|
+
* not need to be true unless encoding to binary string.
|
|
45
|
+
* @returns The original UTF-8/Latin-1 string
|
|
46
|
+
*/
|
|
47
|
+
function strFromU8(data) {
|
|
48
|
+
// https://caniuse.com/?search=TextDecoder
|
|
49
|
+
if (typeof TextDecoder !== 'undefined') {
|
|
50
|
+
return new TextDecoder().decode(data);
|
|
51
|
+
} else {
|
|
52
|
+
return (0, _fflate.strFromU8)(data);
|
|
53
|
+
// Alternatively, it could call a copy-pasted "rest" part of the `strFromU8()` function:
|
|
54
|
+
// const [string, leftovers] = decodeUtf8String(data)
|
|
55
|
+
// console.log(leftovers)
|
|
56
|
+
// if (leftovers.length) {
|
|
57
|
+
// throw new Error('Decode UTF8')
|
|
58
|
+
// }
|
|
59
|
+
// return string
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// This function's code is a copy-paste of `dutf8()` function in `fflate` repository from Jul 12th, 2026.
|
|
64
|
+
// https://github.com/101arrowz/fflate/blob/master/src/index.ts
|
|
65
|
+
//
|
|
66
|
+
// By the way, this function errors when running test case:
|
|
67
|
+
// "made-in-macos-excel-2011-with-custom-font".
|
|
68
|
+
// The leftover is `Uint8Array(2) [ 255, 217 ]`.
|
|
69
|
+
// To reproduce the error, replace the entire `strFromU8()` function
|
|
70
|
+
// in `convertValuesFromUint8ArraysToStrings()` with this function and see what happens.
|
|
71
|
+
//
|
|
72
|
+
// /**
|
|
73
|
+
// * Decodes a `Uint8Array` into a UTF8 string.
|
|
74
|
+
// * @param {Uint8Array} d
|
|
75
|
+
// * @returns {[string, Uint8Array]} — The decoded string and what's left undecoded
|
|
76
|
+
// */
|
|
77
|
+
// export function decodeUtf8String(d) {
|
|
78
|
+
// for (let s = '', i = 0;;) {
|
|
79
|
+
// let c = d[i++]
|
|
80
|
+
// const charType = (c > 127) + (c > 223) + (c > 239)
|
|
81
|
+
// if (i + charType > d.length) {
|
|
82
|
+
// // Returns a slice of an array.
|
|
83
|
+
// // Allows garbage collector to free the original reference.
|
|
84
|
+
// // This function is browser-compatible than `Uint8Array.slice()`.
|
|
85
|
+
// const leftovers = new Uint8Array(d.subarray(i - 1))
|
|
86
|
+
// return [s, leftovers]
|
|
87
|
+
// }
|
|
88
|
+
// if (!charType) {
|
|
89
|
+
// s += String.fromCharCode(c)
|
|
90
|
+
// } else if (charType == 3) {
|
|
91
|
+
// c = ((c & 15) << 18 | (d[i++] & 63) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63)) - 65536
|
|
92
|
+
// s += String.fromCharCode(55296 | (c >> 10), 56320 | (c & 1023))
|
|
93
|
+
// } else if (charType & 1) {
|
|
94
|
+
// s += String.fromCharCode((c & 31) << 6 | (d[i++] & 63))
|
|
95
|
+
// } else {
|
|
96
|
+
// s += String.fromCharCode((c & 15) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63))
|
|
97
|
+
// }
|
|
98
|
+
// }
|
|
99
|
+
// }
|
|
100
|
+
//# sourceMappingURL=convertValuesFromUint8ArraysToStrings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertValuesFromUint8ArraysToStrings.js","names":["_fflate","require","_checkpoint","_interopRequireDefault","obj","__esModule","convertValuesFromUint8ArraysToStrings","entries","checkpoint","convertedEntries","_i","_Object$keys","Object","keys","length","key","strFromU8","data","TextDecoder","decode","strFromU8_"],"sources":["../../source/utility/convertValuesFromUint8ArraysToStrings.js"],"sourcesContent":["// Sidenote: `strFromU8()` function from `fflate` is not \"self-contained\",\r\n// i.e. it references some variables outside of its scope,\r\n// which doesn't work with `worker-f` package and throws an error: \"td is not defined\".\r\n//\r\n// But `woker-f` package is currently not used, so this `import` is not commented out.\r\n//\r\nimport { strFromU8 as strFromU8_ } from 'fflate'\r\n\r\nimport checkpoint from './checkpoint.js'\r\n\r\n/**\r\n * @param {Record<string,Uint8Array} entries\r\n * @returns {Record<string,string>}\r\n */\r\nexport default function convertValuesFromUint8ArraysToStrings(entries) {\r\n\tcheckpoint('convert files to strings')\r\n\tconst convertedEntries = {}\r\n\tfor (const key of Object.keys(entries)) {\r\n\t\tconvertedEntries[key] = strFromU8(entries[key])\r\n\t}\r\n\treturn convertedEntries\r\n}\r\n\r\n// There's a strange thing with using `fflate`'s `strFromU8()` function:\r\n// when `import`ed directly from `fflate` package, the benchmark runs about 10% slower\r\n// then when using `new TextDecoder().decode(data)`, even though `strFromU8()`\r\n// does the same thing internally. So it's a bit mysterious.\r\n//\r\n// Because manually calling `new TextDecoder().decode(data)` is measurably faster for some reason,\r\n// `fflate`'s `strFromU8()` is used as a backup for old web browsers that don't support `TextDecoder`.\r\n//\r\n/**\r\n * Converts a Uint8Array to a string\r\n * @param data The data to decode to string\r\n * @param latin1 Whether or not to interpret the data as Latin-1. This should\r\n * not need to be true unless encoding to binary string.\r\n * @returns The original UTF-8/Latin-1 string\r\n */\r\nexport function strFromU8(data) {\r\n\t// https://caniuse.com/?search=TextDecoder\r\n if (typeof TextDecoder !== 'undefined') {\r\n return new TextDecoder().decode(data)\r\n } else {\r\n\t\treturn strFromU8_(data)\r\n\t\t// Alternatively, it could call a copy-pasted \"rest\" part of the `strFromU8()` function:\r\n // const [string, leftovers] = decodeUtf8String(data)\r\n\t\t// console.log(leftovers)\r\n // if (leftovers.length) {\r\n\t\t// \tthrow new Error('Decode UTF8')\r\n\t\t// }\r\n // return string\r\n }\r\n}\r\n\r\n// This function's code is a copy-paste of `dutf8()` function in `fflate` repository from Jul 12th, 2026.\r\n// https://github.com/101arrowz/fflate/blob/master/src/index.ts\r\n//\r\n// By the way, this function errors when running test case:\r\n// \"made-in-macos-excel-2011-with-custom-font\".\r\n// The leftover is `Uint8Array(2) [ 255, 217 ]`.\r\n// To reproduce the error, replace the entire `strFromU8()` function\r\n// in `convertValuesFromUint8ArraysToStrings()` with this function and see what happens.\r\n//\r\n// /**\r\n// * Decodes a `Uint8Array` into a UTF8 string.\r\n// * @param {Uint8Array} d\r\n// * @returns {[string, Uint8Array]} — The decoded string and what's left undecoded\r\n// */\r\n// export function decodeUtf8String(d) {\r\n// for (let s = '', i = 0;;) {\r\n// let c = d[i++]\r\n// const charType = (c > 127) + (c > 223) + (c > 239)\r\n// if (i + charType > d.length) {\r\n// \t\t\t// Returns a slice of an array.\r\n// \t\t\t// Allows garbage collector to free the original reference.\r\n// \t\t\t// This function is browser-compatible than `Uint8Array.slice()`.\r\n// \t\t\tconst leftovers = new Uint8Array(d.subarray(i - 1))\r\n// \t\t\treturn [s, leftovers]\r\n// \t\t}\r\n// if (!charType) {\r\n// \t\t\ts += String.fromCharCode(c)\r\n// \t\t} else if (charType == 3) {\r\n// c = ((c & 15) << 18 | (d[i++] & 63) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63)) - 65536\r\n// s += String.fromCharCode(55296 | (c >> 10), 56320 | (c & 1023))\r\n// } else if (charType & 1) {\r\n// \t\t\ts += String.fromCharCode((c & 31) << 6 | (d[i++] & 63))\r\n// \t\t} else {\r\n// \t\t\ts += String.fromCharCode((c & 15) << 12 | (d[i++] & 63) << 6 | (d[i++] & 63))\r\n// \t\t}\r\n// }\r\n// }"],"mappings":";;;;;;;AAMA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAwC,SAAAE,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,gBAAAA,GAAA;AARxC;AACA;AACA;AACA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACe,SAASE,qCAAqCA,CAACC,OAAO,EAAE;EACtE,IAAAC,sBAAU,EAAC,0BAA0B,CAAC;EACtC,IAAMC,gBAAgB,GAAG,CAAC,CAAC;EAC3B,SAAAC,EAAA,MAAAC,YAAA,GAAkBC,MAAM,CAACC,IAAI,CAACN,OAAO,CAAC,EAAAG,EAAA,GAAAC,YAAA,CAAAG,MAAA,EAAAJ,EAAA,IAAE;IAAnC,IAAMK,GAAG,GAAAJ,YAAA,CAAAD,EAAA;IACbD,gBAAgB,CAACM,GAAG,CAAC,GAAGC,SAAS,CAACT,OAAO,CAACQ,GAAG,CAAC,CAAC;EAChD;EACA,OAAON,gBAAgB;AACxB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASO,SAASA,CAACC,IAAI,EAAE;EAC/B;EACC,IAAI,OAAOC,WAAW,KAAK,WAAW,EAAE;IACtC,OAAO,IAAIA,WAAW,CAAC,CAAC,CAACC,MAAM,CAACF,IAAI,CAAC;EACvC,CAAC,MAAM;IACP,OAAO,IAAAG,iBAAU,EAACH,IAAI,CAAC;IACvB;IACE;IACF;IACE;IACF;IACA;IACE;EACF;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
14
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
15
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
16
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
17
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
18
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
19
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
20
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
21
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
22
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
23
|
+
var InvalidSpreadsheetError = exports["default"] = /*#__PURE__*/function (_Error) {
|
|
24
|
+
_inherits(InvalidSpreadsheetError, _Error);
|
|
25
|
+
var _super = _createSuper(InvalidSpreadsheetError);
|
|
26
|
+
function InvalidSpreadsheetError(message) {
|
|
27
|
+
var _this;
|
|
28
|
+
_classCallCheck(this, InvalidSpreadsheetError);
|
|
29
|
+
_this = _super.call(this, message);
|
|
30
|
+
|
|
31
|
+
// Set `name` property.
|
|
32
|
+
//
|
|
33
|
+
// This error could be detected either by `instanceof InvalidInputError`
|
|
34
|
+
// or by comparing its `name` property value to "InvalidInputError".
|
|
35
|
+
// Why use the `name` comparison when `instanceof` operator is available?
|
|
36
|
+
// Google AI tells that it does make sense in the cases when an error is
|
|
37
|
+
// "serialized" and then "deserialized" in a "distributed" environment such as
|
|
38
|
+
// throwing an error in a worker thread and then handling it in a main thread,
|
|
39
|
+
// or when throwing it in one "microservice" and then catching it in another one,
|
|
40
|
+
// or just logging as in `sentry.io`. And in those cases, `error.constructor.name`
|
|
41
|
+
// isn't always available for same reason of "serializing" and then "deserializing".
|
|
42
|
+
//
|
|
43
|
+
// For example, even if `InvalidInputError` is a named export of this package,
|
|
44
|
+
// when later bunding the application code with a bundler it will still be minified and renamed.
|
|
45
|
+
// That's when the `name` property could be used to find out the actual type of the error
|
|
46
|
+
// in case it gets thrown and reported to a remote system like `sentry.io`.
|
|
47
|
+
//
|
|
48
|
+
// By the way, core Node.js errors themselves have a `name` property.
|
|
49
|
+
//
|
|
50
|
+
_this.name = 'InvalidSpreadsheetError';
|
|
51
|
+
return _this;
|
|
52
|
+
}
|
|
53
|
+
return _createClass(InvalidSpreadsheetError);
|
|
54
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
55
|
+
//# sourceMappingURL=InvalidSpreadsheetError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvalidSpreadsheetError.js","names":["InvalidSpreadsheetError","exports","_Error","_inherits","_super","_createSuper","message","_this","_classCallCheck","call","name","_createClass","_wrapNativeSuper","Error"],"sources":["../../source/xlsx/InvalidSpreadsheetError.js"],"sourcesContent":["export default class InvalidSpreadsheetError extends Error {\r\n\tconstructor(message) {\r\n\t\tsuper(message)\r\n\r\n\t\t// Set `name` property.\r\n\t\t//\r\n\t\t// This error could be detected either by `instanceof InvalidInputError`\r\n\t\t// or by comparing its `name` property value to \"InvalidInputError\".\r\n\t\t// Why use the `name` comparison when `instanceof` operator is available?\r\n\t\t// Google AI tells that it does make sense in the cases when an error is\r\n\t\t// \"serialized\" and then \"deserialized\" in a \"distributed\" environment such as\r\n\t\t// throwing an error in a worker thread and then handling it in a main thread,\r\n\t\t// or when throwing it in one \"microservice\" and then catching it in another one,\r\n\t\t// or just logging as in `sentry.io`. And in those cases, `error.constructor.name`\r\n\t\t// isn't always available for same reason of \"serializing\" and then \"deserializing\".\r\n\t\t//\r\n\t\t// For example, even if `InvalidInputError` is a named export of this package,\r\n\t\t// when later bunding the application code with a bundler it will still be minified and renamed.\r\n\t\t// That's when the `name` property could be used to find out the actual type of the error\r\n\t\t// in case it gets thrown and reported to a remote system like `sentry.io`.\r\n\t\t//\r\n\t\t// By the way, core Node.js errors themselves have a `name` property.\r\n\t\t//\r\n\t\tthis.name = 'InvalidSpreadsheetError'\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;IAAqBA,uBAAuB,GAAAC,OAAA,qCAAAC,MAAA;EAAAC,SAAA,CAAAH,uBAAA,EAAAE,MAAA;EAAA,IAAAE,MAAA,GAAAC,YAAA,CAAAL,uBAAA;EAC3C,SAAAA,wBAAYM,OAAO,EAAE;IAAA,IAAAC,KAAA;IAAAC,eAAA,OAAAR,uBAAA;IACpBO,KAAA,GAAAH,MAAA,CAAAK,IAAA,OAAMH,OAAO;;IAEb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACAC,KAAA,CAAKG,IAAI,GAAG,yBAAyB;IAAA,OAAAH,KAAA;EACtC;EAAC,OAAAI,YAAA,CAAAX,uBAAA;AAAA,gBAAAY,gBAAA,CAxBmDC,KAAK"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
14
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
15
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
16
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
17
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
18
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
19
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
20
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
21
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
22
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
23
|
+
var SheetNotFoundError = exports["default"] = /*#__PURE__*/function (_Error) {
|
|
24
|
+
_inherits(SheetNotFoundError, _Error);
|
|
25
|
+
var _super = _createSuper(SheetNotFoundError);
|
|
26
|
+
function SheetNotFoundError(message) {
|
|
27
|
+
var _this;
|
|
28
|
+
_classCallCheck(this, SheetNotFoundError);
|
|
29
|
+
_this = _super.call(this, message);
|
|
30
|
+
|
|
31
|
+
// Set `name` property.
|
|
32
|
+
//
|
|
33
|
+
// This error could be detected either by `instanceof InvalidInputError`
|
|
34
|
+
// or by comparing its `name` property value to "InvalidInputError".
|
|
35
|
+
// Why use the `name` comparison when `instanceof` operator is available?
|
|
36
|
+
// Google AI tells that it does make sense in the cases when an error is
|
|
37
|
+
// "serialized" and then "deserialized" in a "distributed" environment such as
|
|
38
|
+
// throwing an error in a worker thread and then handling it in a main thread,
|
|
39
|
+
// or when throwing it in one "microservice" and then catching it in another one,
|
|
40
|
+
// or just logging as in `sentry.io`. And in those cases, `error.constructor.name`
|
|
41
|
+
// isn't always available for same reason of "serializing" and then "deserializing".
|
|
42
|
+
//
|
|
43
|
+
// For example, even if `InvalidInputError` is a named export of this package,
|
|
44
|
+
// when later bunding the application code with a bundler it will still be minified and renamed.
|
|
45
|
+
// That's when the `name` property could be used to find out the actual type of the error
|
|
46
|
+
// in case it gets thrown and reported to a remote system like `sentry.io`.
|
|
47
|
+
//
|
|
48
|
+
// By the way, core Node.js errors themselves have a `name` property.
|
|
49
|
+
//
|
|
50
|
+
_this.name = 'SheetNotFoundError';
|
|
51
|
+
return _this;
|
|
52
|
+
}
|
|
53
|
+
return _createClass(SheetNotFoundError);
|
|
54
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
55
|
+
//# sourceMappingURL=SheetNotFoundError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SheetNotFoundError.js","names":["SheetNotFoundError","exports","_Error","_inherits","_super","_createSuper","message","_this","_classCallCheck","call","name","_createClass","_wrapNativeSuper","Error"],"sources":["../../source/xlsx/SheetNotFoundError.js"],"sourcesContent":["export default class SheetNotFoundError extends Error {\r\n\tconstructor(message) {\r\n\t\tsuper(message)\r\n\r\n\t\t// Set `name` property.\r\n\t\t//\r\n\t\t// This error could be detected either by `instanceof InvalidInputError`\r\n\t\t// or by comparing its `name` property value to \"InvalidInputError\".\r\n\t\t// Why use the `name` comparison when `instanceof` operator is available?\r\n\t\t// Google AI tells that it does make sense in the cases when an error is\r\n\t\t// \"serialized\" and then \"deserialized\" in a \"distributed\" environment such as\r\n\t\t// throwing an error in a worker thread and then handling it in a main thread,\r\n\t\t// or when throwing it in one \"microservice\" and then catching it in another one,\r\n\t\t// or just logging as in `sentry.io`. And in those cases, `error.constructor.name`\r\n\t\t// isn't always available for same reason of \"serializing\" and then \"deserializing\".\r\n\t\t//\r\n\t\t// For example, even if `InvalidInputError` is a named export of this package,\r\n\t\t// when later bunding the application code with a bundler it will still be minified and renamed.\r\n\t\t// That's when the `name` property could be used to find out the actual type of the error\r\n\t\t// in case it gets thrown and reported to a remote system like `sentry.io`.\r\n\t\t//\r\n\t\t// By the way, core Node.js errors themselves have a `name` property.\r\n\t\t//\r\n\t\tthis.name = 'SheetNotFoundError'\r\n\t}\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;IAAqBA,kBAAkB,GAAAC,OAAA,qCAAAC,MAAA;EAAAC,SAAA,CAAAH,kBAAA,EAAAE,MAAA;EAAA,IAAAE,MAAA,GAAAC,YAAA,CAAAL,kBAAA;EACtC,SAAAA,mBAAYM,OAAO,EAAE;IAAA,IAAAC,KAAA;IAAAC,eAAA,OAAAR,kBAAA;IACpBO,KAAA,GAAAH,MAAA,CAAAK,IAAA,OAAMH,OAAO;;IAEb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACAC,KAAA,CAAKG,IAAI,GAAG,oBAAoB;IAAA,OAAAH,KAAA;EACjC;EAAC,OAAAI,YAAA,CAAAX,kBAAA;AAAA,gBAAAY,gBAAA,CAxB8CC,KAAK"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
var _nodeStream = require("node:stream");
|
|
9
|
+
var _createFileTypeDetector = _interopRequireDefault(require("./createFileTypeDetector.js"));
|
|
10
|
+
var _validateLeadingBytes = require("./validateLeadingBytes.js");
|
|
11
|
+
var _InvalidInputError = _interopRequireDefault(require("./InvalidInputError.js"));
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
16
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
17
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
18
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
19
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
20
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
21
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
22
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
23
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
24
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
25
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
26
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
27
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
28
|
+
/**
|
|
29
|
+
* Verifies that an input stream represents a valid `.xlsx` file.
|
|
30
|
+
*
|
|
31
|
+
* Throws an `InvalidInputError` when the input isn't an `.xlsx` file.
|
|
32
|
+
*/
|
|
33
|
+
var InputValidationStream = exports["default"] = /*#__PURE__*/function (_Transform) {
|
|
34
|
+
_inherits(InputValidationStream, _Transform);
|
|
35
|
+
var _super = _createSuper(InputValidationStream);
|
|
36
|
+
function InputValidationStream() {
|
|
37
|
+
var _this;
|
|
38
|
+
_classCallCheck(this, InputValidationStream);
|
|
39
|
+
_this = _super.call(this);
|
|
40
|
+
_this.d = (0, _createFileTypeDetector["default"])();
|
|
41
|
+
_this.i = 0;
|
|
42
|
+
_this.chunks = [];
|
|
43
|
+
return _this;
|
|
44
|
+
}
|
|
45
|
+
_createClass(InputValidationStream, [{
|
|
46
|
+
key: "_transform",
|
|
47
|
+
value: function _transform(chunk, encoding, callback) {
|
|
48
|
+
if (this.d) {
|
|
49
|
+
// Don't send this chunk to the unzipper stream yet,
|
|
50
|
+
// otherwise it might throw an invalid `.zip` archive error
|
|
51
|
+
// before it has detected an `.xls` file.
|
|
52
|
+
this.chunks.push(chunk);
|
|
53
|
+
// Validate the bytes of the chunk.
|
|
54
|
+
for (var _iterator = _createForOfIteratorHelperLoose(chunk), _step; !(_step = _iterator()).done;) {
|
|
55
|
+
var _byte = _step.value;
|
|
56
|
+
try {
|
|
57
|
+
if ((0, _validateLeadingBytes.validateByte)(_byte, this.d)) {
|
|
58
|
+
this.d = undefined;
|
|
59
|
+
chunk = Buffer.concat(this.chunks);
|
|
60
|
+
this.chunks = undefined;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
} catch (error) {
|
|
64
|
+
// Destroy the stream with a validation error,
|
|
65
|
+
// halt further processing and emit an "error" event.
|
|
66
|
+
return callback(error);
|
|
67
|
+
}
|
|
68
|
+
this.i++;
|
|
69
|
+
}
|
|
70
|
+
if (this.d) {
|
|
71
|
+
return callback();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Pass the chunk down to the next stream destination
|
|
76
|
+
this.push(chunk);
|
|
77
|
+
callback();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// `_flush()` is called when there will be no more input, before the "end" event is emitted.
|
|
81
|
+
}, {
|
|
82
|
+
key: "_flush",
|
|
83
|
+
value: function _flush(callback) {
|
|
84
|
+
// If it's still deciding on the file type and there will be no more bytes to read
|
|
85
|
+
// then the file is too short and it should throw an error.
|
|
86
|
+
if (this.d) {
|
|
87
|
+
try {
|
|
88
|
+
(0, _validateLeadingBytes.noFileTypeCouldBeDetermined)(this.i);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
// Destroy the stream with a validation error
|
|
91
|
+
// and emit an "error" event instead of an "end" event.
|
|
92
|
+
return callback(error);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Call the callback to signal that flushing is complete.
|
|
96
|
+
callback();
|
|
97
|
+
}
|
|
98
|
+
}]);
|
|
99
|
+
return InputValidationStream;
|
|
100
|
+
}(_nodeStream.Transform);
|
|
101
|
+
//# sourceMappingURL=InputValidationStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InputValidationStream.js","names":["_nodeStream","require","_createFileTypeDetector","_interopRequireDefault","_validateLeadingBytes","_InvalidInputError","obj","__esModule","_createForOfIteratorHelperLoose","o","allowArrayLike","it","Symbol","iterator","call","next","bind","Array","isArray","_unsupportedIterableToArray","length","i","done","value","TypeError","minLen","_arrayLikeToArray","n","Object","prototype","toString","slice","constructor","name","from","test","arr","len","arr2","_classCallCheck","instance","Constructor","_defineProperties","target","props","descriptor","enumerable","configurable","writable","defineProperty","_toPropertyKey","key","_createClass","protoProps","staticProps","arg","_toPrimitive","_typeof","String","input","hint","prim","toPrimitive","undefined","res","Number","_inherits","subClass","superClass","create","_setPrototypeOf","p","setPrototypeOf","__proto__","_createSuper","Derived","hasNativeReflectConstruct","_isNativeReflectConstruct","_createSuperInternal","Super","_getPrototypeOf","result","NewTarget","Reflect","construct","arguments","apply","_possibleConstructorReturn","self","_assertThisInitialized","ReferenceError","sham","Proxy","Boolean","valueOf","e","getPrototypeOf","InputValidationStream","exports","_Transform","_super","_this","d","createFileTypeDetector","chunks","_transform","chunk","encoding","callback","push","_iterator","_step","byte","validateByte","Buffer","concat","error","_flush","noFileTypeCouldBeDetermined","Transform"],"sources":["../../../source/xlsx/file/InputValidationStream.js"],"sourcesContent":["import { Transform } from 'node:stream'\r\n\r\nimport createFileTypeDetector from './createFileTypeDetector.js'\r\nimport { validateByte, noFileTypeCouldBeDetermined } from './validateLeadingBytes.js'\r\n\r\nimport InvalidInputError from './InvalidInputError.js'\r\n\r\n/**\r\n * Verifies that an input stream represents a valid `.xlsx` file.\r\n *\r\n * Throws an `InvalidInputError` when the input isn't an `.xlsx` file.\r\n */\r\nexport default class InputValidationStream extends Transform {\r\n constructor() {\r\n super()\r\n this.d = createFileTypeDetector()\r\n this.i = 0\r\n this.chunks = []\r\n }\r\n\r\n _transform(chunk, encoding, callback) {\r\n if (this.d) {\r\n // Don't send this chunk to the unzipper stream yet,\r\n // otherwise it might throw an invalid `.zip` archive error\r\n // before it has detected an `.xls` file.\r\n this.chunks.push(chunk)\r\n // Validate the bytes of the chunk.\r\n for (const byte of chunk) {\r\n try {\r\n if (validateByte(byte, this.d)) {\r\n this.d = undefined\r\n chunk = Buffer.concat(this.chunks)\r\n this.chunks = undefined\r\n break\r\n }\r\n } catch (error) {\r\n // Destroy the stream with a validation error,\r\n // halt further processing and emit an \"error\" event.\r\n return callback(error)\r\n }\r\n this.i++\r\n }\r\n if (this.d) {\r\n return callback()\r\n }\r\n }\r\n\r\n // Pass the chunk down to the next stream destination\r\n this.push(chunk)\r\n callback()\r\n }\r\n\r\n // `_flush()` is called when there will be no more input, before the \"end\" event is emitted.\r\n _flush(callback) {\r\n // If it's still deciding on the file type and there will be no more bytes to read\r\n // then the file is too short and it should throw an error.\r\n if (this.d) {\r\n try {\r\n noFileTypeCouldBeDetermined(this.i)\r\n } catch (error) {\r\n // Destroy the stream with a validation error\r\n // and emit an \"error\" event instead of an \"end\" event.\r\n return callback(error)\r\n }\r\n }\r\n // Call the callback to signal that flushing is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AC,CAAC;IACZ;EAAC;EAAA,OAAAX,qBAAA;AAAA,EAvDgDsB,qBAAS"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InputValidationStream.test.js","names":["_mocha","require","_chai","_nodeStream","_InputValidationStream","_interopRequireDefault","obj","__esModule","describe","it","done","XLSX_FILE_FIRST_BYTES","Buffer","from","input","createReadableStreamFromBuffer","inputValidator","InputValidationStream","pipe","on","error","XLS_FILE_FIRST_BYTES","expect","to","have","property","Error","NOT_A_ZIP_FILE_FIRST_BYTES","slice","buffer","Readable"],"sources":["../../../source/xlsx/file/InputValidationStream.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport { Readable } from 'node:stream'\r\n\r\nimport InputValidationStream from './InputValidationStream.js'\r\n\r\ndescribe('InputValidationStream', () => {\r\n\tit('should not throw when ZIP file signature is present', (done) => {\r\n\t\t// \"PK\\x03\\x04\" — a normal ZIP file signature.\r\n\t\tconst XLSX_FILE_FIRST_BYTES = Buffer.from([0x50, 0x4B, 0x03, 0x04])\r\n\r\n\t\tconst input = createReadableStreamFromBuffer(XLSX_FILE_FIRST_BYTES)\r\n\t\tconst inputValidator = new InputValidationStream()\r\n\r\n\t\tinput.pipe(inputValidator)\r\n\t\t\t.on('error', (error) => {\r\n\t\t\t\tdone(error)\r\n\t\t\t})\r\n\t\t\t.on('finish', () => {\r\n\t\t\t\tdone()\r\n\t\t\t})\r\n\t})\r\n\r\n\tit('should throw when it detects a legacy binary `.xls` file (CFB signature)', (done) => {\r\n\t\tconst XLS_FILE_FIRST_BYTES = Buffer.from([0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1])\r\n\r\n\t\tconst input = createReadableStreamFromBuffer(XLS_FILE_FIRST_BYTES)\r\n\t\tconst inputValidator = new InputValidationStream()\r\n\r\n\t\tinput.pipe(inputValidator)\r\n\t\t\t.on('error', (error) => {\r\n\t\t\t\texpect(error).to.have.property('name', 'InvalidInputError')\r\n\t\t\t\texpect(error).to.have.property('code', 'XLS_FILE_NOT_SUPPORTED')\r\n\t\t\t\tdone()\r\n\t\t\t})\r\n\t\t\t.on('finish', () => {\r\n\t\t\t\tdone(new Error('Expected to throw `InvalidInputError`'))\r\n\t\t\t})\r\n\t})\r\n\r\n\tit('should throw when it encounters a non-ZIP file signature', (done) => {\r\n\t\tconst NOT_A_ZIP_FILE_FIRST_BYTES = Buffer.from([0x00, 0x01, 0x02, 0x03])\r\n\r\n\t\tconst input = createReadableStreamFromBuffer(NOT_A_ZIP_FILE_FIRST_BYTES)\r\n\t\tconst inputValidator = new InputValidationStream()\r\n\r\n\t\tinput.pipe(inputValidator)\r\n\t\t\t.on('error', (error) => {\r\n\t\t\t\texpect(error).to.have.property('name', 'InvalidInputError')\r\n\t\t\t\texpect(error).to.have.property('code', 'FILE_NOT_SUPPORTED')\r\n\t\t\t\tdone()\r\n\t\t\t})\r\n\t\t\t.on('finish', () => {\r\n\t\t\t\tdone(new Error('Expected to throw `InvalidInputError`'))\r\n\t\t\t})\r\n\t})\r\n\r\n\tit('should throw when the input is shorter than the ZIP file signature (0 bytes)', (done) => {\r\n\t\tconst XLSX_FILE_FIRST_BYTES = Buffer.from([0x50, 0x4B, 0x03, 0x04])\r\n\r\n\t\tconst input = createReadableStreamFromBuffer(XLSX_FILE_FIRST_BYTES.slice(0, 0))\r\n\t\tconst inputValidator = new InputValidationStream()\r\n\r\n\t\tinput.pipe(inputValidator)\r\n\t\t\t.on('error', (error) => {\r\n\t\t\t\texpect(error).to.have.property('name', 'InvalidInputError')\r\n\t\t\t\texpect(error).to.have.property('code', 'NO_DATA')\r\n\t\t\t\tdone()\r\n\t\t\t})\r\n\t\t\t.on('finish', () => {\r\n\t\t\t\tdone(new Error('Expected to throw `InvalidInputError`'))\r\n\t\t\t})\r\n\t})\r\n\r\n\tit('should throw when the input is shorter than the ZIP file signature (1 byte)', (done) => {\r\n\t\tconst XLSX_FILE_FIRST_BYTES = Buffer.from([0x50, 0x4B, 0x03, 0x04])\r\n\r\n\t\tconst input = createReadableStreamFromBuffer(XLSX_FILE_FIRST_BYTES.slice(0, 1))\r\n\t\tconst inputValidator = new InputValidationStream()\r\n\r\n\t\tinput.pipe(inputValidator)\r\n\t\t\t.on('error', (error) => {\r\n\t\t\t\texpect(error).to.have.property('name', 'InvalidInputError')\r\n\t\t\t\texpect(error).to.have.property('code', 'FILE_NOT_SUPPORTED')\r\n\t\t\t\tdone()\r\n\t\t\t})\r\n\t\t\t.on('finish', () => {\r\n\t\t\t\tdone(new Error('Expected to throw `InvalidInputError`'))\r\n\t\t\t})\r\n\t})\r\n\r\n\tit('should not throw when the input is not shorter than a bare minimum ZIP file signature (2 bytes)', (done) => {\r\n\t\tconst XLSX_FILE_FIRST_BYTES = Buffer.from([0x50, 0x4B, 0x03, 0x04])\r\n\r\n\t\tconst input = createReadableStreamFromBuffer(XLSX_FILE_FIRST_BYTES.slice(0, 2))\r\n\t\tconst inputValidator = new InputValidationStream()\r\n\r\n\t\tinput.pipe(inputValidator)\r\n\t\t\t.on('error', (error) => {\r\n\t\t\t\tdone(error)\r\n\t\t\t})\r\n\t\t\t.on('finish', () => {\r\n\t\t\t\tdone()\r\n\t\t\t})\r\n\t})\r\n})\r\n\r\n// Creates a readable stream from a `Buffer`.\r\nfunction createReadableStreamFromBuffer(buffer) {\r\n\treturn Readable.from(buffer)\r\n}\r\n"],"mappings":";;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAF,OAAA;AAEA,IAAAG,sBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAA8D,SAAAI,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,gBAAAA,GAAA;AAE9D,IAAAE,eAAQ,EAAC,uBAAuB,EAAE,YAAM;EACvC,IAAAC,SAAE,EAAC,qDAAqD,EAAE,UAACC,IAAI,EA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AAC,iGAAiG,EAAE,UAACC,IAAI,EAAK;IAC/G,IAAMC,qBAAqB,GAAGC,MAAM,CAACC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAEnE,IAAMC,KAAK,GAAGC,8BAA8B,CAACJ,qBAAqB,CAACiB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/E,IAAMZ,cAAc,GAAG,IAAIC,iCAAqB,CAAC,CAAC;IAElDH,KAAK,CAACI,IAAI,CAACF,cAAc,CAAC,CACxBG,EAAE,CAAC,OAAO,EAAE,UAACC,KAAK,EAAK;MACvBV,IAAI,CAACU,KAAK,CAAC;IACZ,CAAC,CAAC,CACDD,EAAE,CAAC,QAAQ,EAAE,YAAM;MACnBT,IAAI,CAAC,CAAC;IACP,CAAC,CAAC;EACJ,CAAC,CAAC;AACH,CAAC,CAAC;;AAEF;AACA,SAASK,8BAA8BA,CAACc,MAAM,EAAE;EAC/C,OAAOC,oBAAQ,CAACjB,IAAI,CAACgB,MAAM,CAAC;AAC7B"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports["default"] = void 0;
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
14
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
15
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
16
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
17
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
18
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
19
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
20
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
21
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
22
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
23
|
+
// This code was originally submitted by Etienne Prothon.
|
|
24
|
+
// https://gitlab.com/catamphetamine/read-excel-file/-/merge_requests/11
|
|
25
|
+
|
|
26
|
+
// An error thrown when the input passed to `readXlsxFile()` is not a valid `.xlsx` file.
|
|
27
|
+
//
|
|
28
|
+
// Carries a documented, stable `code` property that consumers can reliably
|
|
29
|
+
// branch on — same convention as the schema-parsing `InvalidError` class
|
|
30
|
+
// (`error.code`) — instead of string-matching a low-level error message
|
|
31
|
+
// leaked from a transitive dependency (Hyrum's law).
|
|
32
|
+
//
|
|
33
|
+
// The `name` property is set so that the error type can also be detected via
|
|
34
|
+
// `error.name === 'InvalidInputError'` in setups where `instanceof` is unreliable
|
|
35
|
+
// (e.g. when both the ES-module and the CommonJS builds of this package end up
|
|
36
|
+
// being loaded in the same application).
|
|
37
|
+
|
|
38
|
+
var MESSAGES = {
|
|
39
|
+
XLS_FILE_NOT_SUPPORTED: 'You passed a legacy `.xls` file. Only `.xlsx` files are supported',
|
|
40
|
+
FILE_NOT_SUPPORTED: 'Doesn\'t look like an `.xlsx` file',
|
|
41
|
+
INVALID_ZIP: 'Couldn\'t unzip `.xlsx` file contents',
|
|
42
|
+
NO_DATA: 'No data'
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// `.xlsx` files are just ZIP archives, so every valid `.xlsx` file starts with a
|
|
46
|
+
// ZIP local file header signature "PK" (`0x50 0x4B`). When the input isn't a ZIP
|
|
47
|
+
// archive, a 3rd-party unzipper library throws an obscure low-level error
|
|
48
|
+
// (for example `"invalid signature: 0xe011cfd0"` — the four leading bytes of a
|
|
49
|
+
// binary `.xls` file read in little-endian).
|
|
50
|
+
// That gives the caller nothing stable to branch on, and the exact wording can change
|
|
51
|
+
// depending on the 3rd-party unzipper library being used.
|
|
52
|
+
// This error standardizes the handling of cases when an invalid file is passed.
|
|
53
|
+
var InvalidInputError = exports["default"] = /*#__PURE__*/function (_Error) {
|
|
54
|
+
_inherits(InvalidInputError, _Error);
|
|
55
|
+
var _super = _createSuper(InvalidInputError);
|
|
56
|
+
/**
|
|
57
|
+
* Creates an `InvalidInputError` instance.
|
|
58
|
+
* @param {string} code
|
|
59
|
+
* @param {any} [cause]
|
|
60
|
+
*/
|
|
61
|
+
function InvalidInputError(code, cause) {
|
|
62
|
+
var _this;
|
|
63
|
+
_classCallCheck(this, InvalidInputError);
|
|
64
|
+
_this = _super.call(this, MESSAGES[code] || code);
|
|
65
|
+
|
|
66
|
+
// Set `code` property.
|
|
67
|
+
_this.code = code;
|
|
68
|
+
|
|
69
|
+
// Set `name` property.
|
|
70
|
+
//
|
|
71
|
+
// This error could be detected either by `instanceof InvalidInputError`
|
|
72
|
+
// or by comparing its `name` property value to "InvalidInputError".
|
|
73
|
+
// Why use the `name` comparison when `instanceof` operator is available?
|
|
74
|
+
// Google AI tells that it does make sense in the cases when an error is
|
|
75
|
+
// "serialized" and then "deserialized" in a "distributed" environment such as
|
|
76
|
+
// throwing an error in a worker thread and then handling it in a main thread,
|
|
77
|
+
// or when throwing it in one "microservice" and then catching it in another one,
|
|
78
|
+
// or just logging as in `sentry.io`. And in those cases, `error.constructor.name`
|
|
79
|
+
// isn't always available for same reason of "serializing" and then "deserializing".
|
|
80
|
+
//
|
|
81
|
+
// For example, even if `InvalidInputError` is a named export of this package,
|
|
82
|
+
// when later bunding the application code with a bundler it will still be minified and renamed.
|
|
83
|
+
// That's when the `name` property could be used to find out the actual type of the error
|
|
84
|
+
// in case it gets thrown and reported to a remote system like `sentry.io`.
|
|
85
|
+
//
|
|
86
|
+
// By the way, core Node.js errors themselves have a `name` property.
|
|
87
|
+
//
|
|
88
|
+
_this.name = 'InvalidInputError';
|
|
89
|
+
|
|
90
|
+
// Set `cause` property.
|
|
91
|
+
//
|
|
92
|
+
// `Error.prototype.cause` property indicates the specific, original reason
|
|
93
|
+
// a given error occurred. Standardized in ES2022, it allows you to chain errors
|
|
94
|
+
// by catching a low-level exception and re-throwing a meaningful, high-level error
|
|
95
|
+
// without wiping out the diagnostic context or stack trace of the original failure.
|
|
96
|
+
//
|
|
97
|
+
// Adding a `.cause` property mimics modern error chaining for environments that support it
|
|
98
|
+
// while remaining completely harmless in older systems.
|
|
99
|
+
//
|
|
100
|
+
_this.cause = cause;
|
|
101
|
+
return _this;
|
|
102
|
+
}
|
|
103
|
+
return _createClass(InvalidInputError);
|
|
104
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
105
|
+
//# sourceMappingURL=InvalidInputError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvalidInputError.js","names":["MESSAGES","XLS_FILE_NOT_SUPPORTED","FILE_NOT_SUPPORTED","INVALID_ZIP","NO_DATA","InvalidInputError","exports","_Error","_inherits","_super","_createSuper","code","cause","_this","_classCallCheck","call","name","_createClass","_wrapNativeSuper","Error"],"sources":["../../../source/xlsx/file/InvalidInputError.js"],"sourcesContent":["// This code was originally submitted by Etienne Prothon.\r\n// https://gitlab.com/catamphetamine/read-excel-file/-/merge_requests/11\r\n\r\n// An error thrown when the input passed to `readXlsxFile()` is not a valid `.xlsx` file.\r\n//\r\n// Carries a documented, stable `code` property that consumers can reliably\r\n// branch on — same convention as the schema-parsing `InvalidError` class\r\n// (`error.code`) — instead of string-matching a low-level error message\r\n// leaked from a transitive dependency (Hyrum's law).\r\n//\r\n// The `name` property is set so that the error type can also be detected via\r\n// `error.name === 'InvalidInputError'` in setups where `instanceof` is unreliable\r\n// (e.g. when both the ES-module and the CommonJS builds of this package end up\r\n// being loaded in the same application).\r\n\r\nconst MESSAGES = {\r\n\tXLS_FILE_NOT_SUPPORTED:\r\n\t\t'You passed a legacy `.xls` file. Only `.xlsx` files are supported',\r\n\tFILE_NOT_SUPPORTED:\r\n\t\t'Doesn\\'t look like an `.xlsx` file',\r\n\tINVALID_ZIP:\r\n\t\t'Couldn\\'t unzip `.xlsx` file contents',\r\n\tNO_DATA:\r\n\t\t'No data'\r\n}\r\n\r\n// `.xlsx` files are just ZIP archives, so every valid `.xlsx` file starts with a\r\n// ZIP local file header signature \"PK\" (`0x50 0x4B`). When the input isn't a ZIP\r\n// archive, a 3rd-party unzipper library throws an obscure low-level error\r\n// (for example `\"invalid signature: 0xe011cfd0\"` — the four leading bytes of a\r\n// binary `.xls` file read in little-endian).\r\n// That gives the caller nothing stable to branch on, and the exact wording can change\r\n// depending on the 3rd-party unzipper library being used.\r\n// This error standardizes the handling of cases when an invalid file is passed.\r\nexport default class InvalidInputError extends Error {\r\n\t/**\r\n\t * Creates an `InvalidInputError` instance.\r\n\t * @param {string} code\r\n\t * @param {any} [cause]\r\n\t */\r\n\tconstructor(code, cause) {\r\n\t\tsuper(MESSAGES[code] || code)\r\n\r\n\t\t// Set `code` property.\r\n\t\tthis.code = code\r\n\r\n\t\t// Set `name` property.\r\n\t\t//\r\n\t\t// This error could be detected either by `instanceof InvalidInputError`\r\n\t\t// or by comparing its `name` property value to \"InvalidInputError\".\r\n\t\t// Why use the `name` comparison when `instanceof` operator is available?\r\n\t\t// Google AI tells that it does make sense in the cases when an error is\r\n\t\t// \"serialized\" and then \"deserialized\" in a \"distributed\" environment such as\r\n\t\t// throwing an error in a worker thread and then handling it in a main thread,\r\n\t\t// or when throwing it in one \"microservice\" and then catching it in another one,\r\n\t\t// or just logging as in `sentry.io`. And in those cases, `error.constructor.name`\r\n\t\t// isn't always available for same reason of \"serializing\" and then \"deserializing\".\r\n\t\t//\r\n\t\t// For example, even if `InvalidInputError` is a named export of this package,\r\n\t\t// when later bunding the application code with a bundler it will still be minified and renamed.\r\n\t\t// That's when the `name` property could be used to find out the actual type of the error\r\n\t\t// in case it gets thrown and reported to a remote system like `sentry.io`.\r\n\t\t//\r\n\t\t// By the way, core Node.js errors themselves have a `name` property.\r\n\t\t//\r\n\t\tthis.name = 'InvalidInputError'\r\n\r\n\t\t// Set `cause` property.\r\n\t\t//\r\n\t\t// `Error.prototype.cause` property indicates the specific, original reason\r\n\t\t// a given error occurred. Standardized in ES2022, it allows you to chain errors\r\n\t\t// by catching a low-level exception and re-throwing a meaningful, high-level error\r\n\t\t// without wiping out the diagnostic context or stack trace of the original failure.\r\n\t\t//\r\n\t\t// Adding a `.cause` property mimics modern error chaining for environments that support it\r\n\t\t// while remaining completely harmless in older systems.\r\n\t\t//\r\n\t\tthis.cause = cause\r\n\t}\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,IAAMA,QAAQ,GAAG;EAChBC,sBAAsB,EACrB,mEAAmE;EACpEC,kBAAkB,EACjB,oCAAoC;EACrCC,WAAW,EACV,uCAAuC;EACxCC,OAAO,EACN;AACF,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA,IACqBC,iBAAiB,GAAAC,OAAA,qCAAAC,MAAA;EAAAC,SAAA,CAAAH,iBAAA,EAAAE,MAAA;EAAA,IAAAE,MAAA,GAAAC,YAAA,CAAAL,iBAAA;EACrC;AACD;AACA;AACA;AACA;EACC,SAAAA,kBAAYM,IAAI,EAAEC,KAAK,EAAE;IAAA,IAAAC,KAAA;IAAAC,eAAA,OAAAT,iBAAA;IACxBQ,KAAA,GAAAJ,MAAA,CAAAM,IAAA,OAAMf,QAAQ,CAACW,IAAI,CAAC,IAAIA,IAAI;;IAE5B;IACAE,KAAA,CAAKF,IAAI,GAAGA,IAAI;;IAEhB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACAE,KAAA,CAAKG,IAAI,GAAG,mBAAmB;;IAE/B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACAH,KAAA,CAAKD,KAAK,GAAGA,KAAK;IAAA,OAAAC,KAAA;EACnB;EAAC,OAAAI,YAAA,CAAAZ,iBAAA;AAAA,gBAAAa,gBAAA,CA5C6CC,KAAK"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.XLS_FILE_TYPE = exports.XLSX_FILE_TYPE = void 0;
|
|
7
|
+
exports["default"] = createFileTypeDetector;
|
|
8
|
+
// This code was originally submitted by Etienne Prothon.
|
|
9
|
+
// https://gitlab.com/catamphetamine/read-excel-file/-/merge_requests/11
|
|
10
|
+
|
|
11
|
+
// ZIP local file header signature: "PK\x03\x04". The first two bytes "PK" are
|
|
12
|
+
// shared by every ZIP variant (including the empty-archive `PK\x05\x06` and the
|
|
13
|
+
// spanned `PK\x07\x08` markers), so matching just "PK" up front avoids rejecting
|
|
14
|
+
// any valid — if unusual — archive; anything malformed past that point is still
|
|
15
|
+
// caught by the actual unzipper.
|
|
16
|
+
var ZIP_FILE_SIGNATURE = [0x50, 0x4B];
|
|
17
|
+
|
|
18
|
+
// The first four bytes of the OLE2 Compound File Binary format (`0xD0 0xCF 0x11 0xE0`),
|
|
19
|
+
// which is the container of legacy binary `.xls` files.
|
|
20
|
+
var XLS_FILE_SIGNATURE = [0xD0, 0xCF, 0x11, 0xE0];
|
|
21
|
+
var FILE_TYPE_SIGNATURES = [ZIP_FILE_SIGNATURE, XLS_FILE_SIGNATURE];
|
|
22
|
+
|
|
23
|
+
// File type "enum".
|
|
24
|
+
var XLSX_FILE_TYPE = exports.XLSX_FILE_TYPE = FILE_TYPE_SIGNATURES.indexOf(ZIP_FILE_SIGNATURE);
|
|
25
|
+
var XLS_FILE_TYPE = exports.XLS_FILE_TYPE = FILE_TYPE_SIGNATURES.indexOf(XLS_FILE_SIGNATURE);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Creates a function get determines a file type based on the leading bytes.
|
|
29
|
+
* @return {function} A function that receives a `byte` (an element of a `Uint8Array`) and returns a `type: number?` — an index in the file types "enum", or `-1` if it doesn't match any file type, or `undefined` if it's still deciding on the file type.
|
|
30
|
+
* @throws {InvalidInputError}
|
|
31
|
+
*/
|
|
32
|
+
function createFileTypeDetector() {
|
|
33
|
+
var type;
|
|
34
|
+
var possibleTypes = indexesOf(FILE_TYPE_SIGNATURES);
|
|
35
|
+
var i = 0;
|
|
36
|
+
// Returns a function that should be called for each leading byte of the file
|
|
37
|
+
// until it starts returning a number.
|
|
38
|
+
return function (_byte) {
|
|
39
|
+
// If the type of the file is still being determined.
|
|
40
|
+
if (isNaN(type)) {
|
|
41
|
+
var t;
|
|
42
|
+
possibleTypes = possibleTypes.filter(function (typeIndex) {
|
|
43
|
+
if (_byte === FILE_TYPE_SIGNATURES[typeIndex][i]) {
|
|
44
|
+
if (FILE_TYPE_SIGNATURES[typeIndex].length === i + 1) {
|
|
45
|
+
t = typeIndex;
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
if (possibleTypes.length === 1) {
|
|
51
|
+
type = t;
|
|
52
|
+
} else if (possibleTypes.length === 0) {
|
|
53
|
+
// `type: -1` means "the type of the file couldn't be determined"
|
|
54
|
+
type = -1;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
i++;
|
|
58
|
+
return type;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function indexesOf(array) {
|
|
62
|
+
var indexes = [];
|
|
63
|
+
var i = 0;
|
|
64
|
+
while (i < array.length) {
|
|
65
|
+
indexes.push(i);
|
|
66
|
+
i++;
|
|
67
|
+
}
|
|
68
|
+
return indexes;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=createFileTypeDetector.js.map
|