read-excel-file 9.3.4 → 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 +6 -2
- 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/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/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 -189
- 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 -183
- 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,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 complete.\r\n callback()\r\n }\r\n}"],"mappings":";;;;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAEA,IAAAC,uBAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,qBAAA,GAAAH,OAAA;AAEA,IAAAI,kBAAA,GAAAF,sBAAA,CAAAF,OAAA;AAAsD,SAAAE,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,gBAAAA,GAAA;AAAA,SAAAE,gCAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,MAAA,oBAAAH,CAAA,CAAAG,MAAA,CAAAC,QAAA,KAAAJ,CAAA,oB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A0F,kCAAY,EAACD,KAAI,EAAE,IAAI,CAACV,CAAC,CAAC,EAAE;cAC9B,IAAI,CAACA,CAAC,GAAGvC,SAAS;cAClB2C,KAAK,GAAGQ,MAAM,CAACC,MAAM,CAAC,IAAI,CAACX,MAAM,CAAC;cAClC,IAAI,CAACA,MAAM,GAAGzC,SAAS;cACvB;YACF;UACF,CAAC,CAAC,OAAOqD,KAAK,EAAE;YACd;YACA;YACA,OAAOR,QAAQ,CAACQ,KAAK,CAAC;UACxB;UACA,IAAI,CAAC/F,CAAC,EAAE;QACV;QACA,IAAI,IAAI,CAACiF,CAAC,EAAE;UACV,OAAOM,QAAQ,CAAC,CAAC;QACnB;MACF;;MAEA;MACA,IAAI,CAACC,IAAI,CAACH,KAAK,CAAC;MAChBE,QAAQ,CAAC,CAAC;IACZ;;IAEA;EAAA;IAAAzD,GAAA;IAAA5B,KAAA,EACA,SAAA8F,OAAOT,QAAQ,EAAE;MACf;MACA;MACA,IAAI,IAAI,CAACN,CAAC,EAAE;QACV,IAAI;UACF,IAAAgB,iDAA2B,EAAC,IAAI,CAACjG,CAAC,CAAC;QACrC,CAAC,CAAC,OAAO+F,KAAK,EAAE;UACd;UACA;UACA,OAAOR,QAAQ,CAACQ,KAAK,CAAC;QACxB;MACF;MACA;MACAR,QAAQ,CAAC,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,EAAK;IACnE;IACA,IAAMC,qBAAqB,GAAGC,MAAM,CAACC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAEnE,IAAMC,KAAK,GAAGC,8BAA8B,CAACJ,qBAAqB,CAAC;IACnE,IAAMK,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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K,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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFileTypeDetector.js","names":["ZIP_FILE_SIGNATURE","XLS_FILE_SIGNATURE","FILE_TYPE_SIGNATURES","XLSX_FILE_TYPE","exports","indexOf","XLS_FILE_TYPE","createFileTypeDetector","type","possibleTypes","indexesOf","i","byte","isNaN","t","filter","typeIndex","length","array","indexes","push"],"sources":["../../../source/xlsx/file/createFileTypeDetector.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// ZIP local file header signature: \"PK\\x03\\x04\". The first two bytes \"PK\" are\r\n// shared by every ZIP variant (including the empty-archive `PK\\x05\\x06` and the\r\n// spanned `PK\\x07\\x08` markers), so matching just \"PK\" up front avoids rejecting\r\n// any valid — if unusual — archive; anything malformed past that point is still\r\n// caught by the actual unzipper.\r\nconst ZIP_FILE_SIGNATURE = [0x50, 0x4B]\r\n\r\n// The first four bytes of the OLE2 Compound File Binary format (`0xD0 0xCF 0x11 0xE0`),\r\n// which is the container of legacy binary `.xls` files.\r\nconst XLS_FILE_SIGNATURE = [0xD0, 0xCF, 0x11, 0xE0]\r\n\r\nconst FILE_TYPE_SIGNATURES = [\r\n\tZIP_FILE_SIGNATURE,\r\n\tXLS_FILE_SIGNATURE\r\n]\r\n\r\n// File type \"enum\".\r\nexport const XLSX_FILE_TYPE = FILE_TYPE_SIGNATURES.indexOf(ZIP_FILE_SIGNATURE)\r\nexport const XLS_FILE_TYPE = FILE_TYPE_SIGNATURES.indexOf(XLS_FILE_SIGNATURE)\r\n\r\n/**\r\n * Creates a function get determines a file type based on the leading bytes.\r\n * @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.\r\n * @throws {InvalidInputError}\r\n */\r\nexport default function createFileTypeDetector() {\r\n\tlet type\r\n\tlet possibleTypes = indexesOf(FILE_TYPE_SIGNATURES)\r\n\tlet i = 0\r\n\t// Returns a function that should be called for each leading byte of the file\r\n\t// until it starts returning a number.\r\n\treturn (byte) => {\r\n\t\t// If the type of the file is still being determined.\r\n\t\tif (isNaN(type)) {\r\n\t\t\tlet t\r\n\t\t\tpossibleTypes = possibleTypes.filter((typeIndex) => {\r\n\t\t\t\tif (byte === FILE_TYPE_SIGNATURES[typeIndex][i]) {\r\n\t\t\t\t\tif (FILE_TYPE_SIGNATURES[typeIndex].length === i + 1) {\r\n\t\t\t\t\t\tt = typeIndex\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn true\r\n\t\t\t\t}\r\n\t\t\t})\r\n\t\t\tif (possibleTypes.length === 1) {\r\n\t\t\t\ttype = t\r\n\t\t\t} else if (possibleTypes.length === 0) {\r\n\t\t\t\t// `type: -1` means \"the type of the file couldn't be determined\"\r\n\t\t\t\ttype = -1\r\n\t\t\t}\r\n\t\t}\r\n\t\ti++\r\n\t\treturn type\r\n\t}\r\n}\r\n\r\nfunction indexesOf(array) {\r\n\tconst indexes = []\r\n\tlet i = 0\r\n\twhile (i < array.length) {\r\n\t\tindexes.push(i)\r\n\t\ti++\r\n\t}\r\n\treturn indexes\r\n}"],"mappings":";;;;;;;AAAA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,IAAMA,kBAAkB,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC;;AAEvC;AACA;AACA,IAAMC,kBAAkB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE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AO,CAACC,IAAI,CAACT,CAAC,CAAC;IACfA,CAAC,EAAE;EACJ;EACA,OAAOQ,OAAO;AACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFileTypeDetector.test.js","names":["_mocha","require","_chai","_createFileTypeDetector","_interopRequireWildcard","_InvalidInputError","_interopRequireDefault","obj","__esModule","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","describe","it","XLSX_FILE_FIRST_BYTES","fileTypeDetector","createFileTypeDetector","expect","to","be","undefined","equal","XLSX_FILE_TYPE","XLS_FILE_FIRST_BYTES","XLS_FILE_TYPE","NOT_A_ZIP_FILE_FIRST_BYTES"],"sources":["../../../source/xlsx/file/createFileTypeDetector.test.js"],"sourcesContent":["import { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport createFileTypeDetector, { XLSX_FILE_TYPE, XLS_FILE_TYPE } from './createFileTypeDetector.js'\r\nimport InvalidInputError from './InvalidInputError.js'\r\n\r\ndescribe('createFileTypeDetector', () => {\r\n\tit('should not throw when ZIP file signature is present', () => {\r\n\t\t// \"PK\\x03\\x04\" — a normal ZIP file signature.\r\n\t\tconst XLSX_FILE_FIRST_BYTES = [0x50, 0x4B, 0x03, 0x04]\r\n\t\tconst fileTypeDetector = createFileTypeDetector()\r\n\t\texpect(fileTypeDetector(XLSX_FILE_FIRST_BYTES[0])).to.be.undefined\r\n\t\texpect(fileTypeDetector(XLSX_FILE_FIRST_BYTES[1])).to.equal(XLSX_FILE_TYPE)\r\n\t\texpect(fileTypeDetector(XLSX_FILE_FIRST_BYTES[2])).to.equal(XLSX_FILE_TYPE)\r\n\t\texpect(fileTypeDetector(XLSX_FILE_FIRST_BYTES[3])).to.equal(XLSX_FILE_TYPE)\r\n\t})\r\n\r\n\tit('should throw when it detects a legacy binary `.xls` file (CFB signature)', () => {\r\n\t\tconst XLS_FILE_FIRST_BYTES = [0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1]\r\n\t\tconst fileTypeDetector = createFileTypeDetector()\r\n\t\texpect(fileTypeDetector(XLS_FILE_FIRST_BYTES[0])).to.be.undefined\r\n\t\texpect(fileTypeDetector(XLS_FILE_FIRST_BYTES[1])).to.be.undefined\r\n\t\texpect(fileTypeDetector(XLS_FILE_FIRST_BYTES[2])).to.be.undefined\r\n\t\texpect(fileTypeDetector(XLS_FILE_FIRST_BYTES[3])).to.equal(XLS_FILE_TYPE)\r\n\t\texpect(fileTypeDetector(XLS_FILE_FIRST_BYTES[4])).to.equal(XLS_FILE_TYPE)\r\n\t\texpect(fileTypeDetector(XLS_FILE_FIRST_BYTES[5])).to.equal(XLS_FILE_TYPE)\r\n\t\texpect(fileTypeDetector(XLS_FILE_FIRST_BYTES[6])).to.equal(XLS_FILE_TYPE)\r\n\t\texpect(fileTypeDetector(XLS_FILE_FIRST_BYTES[6])).to.equal(XLS_FILE_TYPE)\r\n\t})\r\n\r\n\tit('should throw when it encounters a non-ZIP file signature', () => {\r\n\t\tconst NOT_A_ZIP_FILE_FIRST_BYTES = [0x00, 0x01, 0x02, 0x03]\r\n\t\tconst fileTypeDetector = createFileTypeDetector()\r\n\t\texpect(fileTypeDetector(NOT_A_ZIP_FILE_FIRST_BYTES[0])).to.equal(-1)\r\n\t\texpect(fileTypeDetector(NOT_A_ZIP_FILE_FIRST_BYTES[1])).to.equal(-1)\r\n\t\texpect(fileTypeDetector(NOT_A_ZIP_FILE_FIRST_BYTES[2])).to.equal(-1)\r\n\t\texpect(fileTypeDetector(NOT_A_ZIP_FILE_FIRST_BYTES[3])).to.equal(-1)\r\n\t})\r\n})\r\n"],"mappings":";;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,uBAAA,GAAAC,uBAAA,CAAAH,OAAA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CAACP,EAAE,CAACG,KAAK,CAAC,CAAC,CAAC,CAAC;IACpE,IAAAJ,YAAM,EAACF,gBAAgB,CAACU,0BAA0B,CAAC,CAAC,CAAC,CAAC,CAAC,CAACP,EAAE,CAACG,KAAK,CAAC,CAAC,CAAC,CAAC;EACrE,CAAC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
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"] = validateLeadingBytes;
|
|
8
|
+
exports.noFileTypeCouldBeDetermined = noFileTypeCouldBeDetermined;
|
|
9
|
+
exports.validateByte = validateByte;
|
|
10
|
+
var _InvalidInputError = _interopRequireDefault(require("./InvalidInputError.js"));
|
|
11
|
+
var _createFileTypeDetector = _interopRequireWildcard(require("./createFileTypeDetector.js"));
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
|
+
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."); }
|
|
16
|
+
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); }
|
|
17
|
+
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; } // This code was originally submitted by Etienne Prothon.
|
|
18
|
+
// https://gitlab.com/catamphetamine/read-excel-file/-/merge_requests/11
|
|
19
|
+
function validateLeadingBytes(bytes) {
|
|
20
|
+
var fileTypeDetector = (0, _createFileTypeDetector["default"])();
|
|
21
|
+
for (var _iterator = _createForOfIteratorHelperLoose(bytes), _step; !(_step = _iterator()).done;) {
|
|
22
|
+
var _byte = _step.value;
|
|
23
|
+
if (validateByte(_byte, fileTypeDetector)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
noFileTypeCouldBeDetermined(bytes.length);
|
|
28
|
+
}
|
|
29
|
+
function validateByte(_byte2, fileTypeDetector) {
|
|
30
|
+
var fileType = fileTypeDetector(_byte2);
|
|
31
|
+
if (fileType !== undefined) {
|
|
32
|
+
// If it has determined that the file type is `.xls`.
|
|
33
|
+
if (fileType === _createFileTypeDetector.XLS_FILE_TYPE) {
|
|
34
|
+
throw new _InvalidInputError["default"]('XLS_FILE_NOT_SUPPORTED');
|
|
35
|
+
}
|
|
36
|
+
// If it has determined that the file type is none of the known ones.
|
|
37
|
+
if (fileType < 0) {
|
|
38
|
+
throw new _InvalidInputError["default"]('FILE_NOT_SUPPORTED');
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function noFileTypeCouldBeDetermined(byteCount) {
|
|
44
|
+
// The file type couldn't be determined — not enough bytes.
|
|
45
|
+
throw new _InvalidInputError["default"](byteCount === 0 ? 'NO_DATA' : 'FILE_NOT_SUPPORTED');
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=validateLeadingBytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateLeadingBytes.js","names":["_InvalidInputError","_interopRequireDefault","require","_createFileTypeDetector","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","_typeof","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_createForOfIteratorHelperLoose","o","allowArrayLike","it","Symbol","iterator","next","bind","Array","isArray","_unsupportedIterableToArray","length","i","done","value","TypeError","minLen","_arrayLikeToArray","n","toString","slice","constructor","name","from","test","arr","len","arr2","validateLeadingBytes","bytes","fileTypeDetector","createFileTypeDetector","_iterator","_step","byte","validateByte","noFileTypeCouldBeDetermined","fileType","undefined","XLS_FILE_TYPE","InvalidInputError","byteCount"],"sources":["../../../source/xlsx/file/validateLeadingBytes.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\nimport InvalidInputError from './InvalidInputError.js'\r\nimport createFileTypeDetector, { XLS_FILE_TYPE } from './createFileTypeDetector.js'\r\n\r\nexport default function validateLeadingBytes(bytes) {\r\n\tconst fileTypeDetector = createFileTypeDetector()\r\n\r\n\tfor (const byte of bytes) {\r\n\t\tif (validateByte(byte, fileTypeDetector)) {\r\n\t\t\treturn\r\n\t\t}\r\n\t}\r\n\r\n\tnoFileTypeCouldBeDetermined(bytes.length)\r\n}\r\n\r\nexport function validateByte(byte, fileTypeDetector) {\r\n\tconst fileType = fileTypeDetector(byte)\r\n\tif (fileType !== undefined) {\r\n\t\t// If it has determined that the file type is `.xls`.\r\n\t\tif (fileType === XLS_FILE_TYPE) {\r\n\t\t\tthrow new InvalidInputError('XLS_FILE_NOT_SUPPORTED')\r\n\t\t}\r\n\t\t// If it has determined that the file type is none of the known ones.\r\n\t\tif (fileType < 0) {\r\n\t\t\tthrow new InvalidInputError('FILE_NOT_SUPPORTED')\r\n\t\t}\r\n\t\treturn true\r\n\t}\r\n}\r\n\r\nexport function noFileTypeCouldBeDetermined(byteCount) {\r\n\t// The file type couldn't be determined — not enough bytes.\r\n\tthrow new InvalidInputError(byteCount === 0 ? 'NO_DATA' : 'FILE_NOT_SUPPORTED')\r\n}"],"mappings":";;;;;;;;;AAGA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,uBAAA,GAAAC,uBAAA,CAAAF,OAAA;AAAmF,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,yBAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAF,wBAAAM,G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AnB,IAAA,GAAE;IAAA,IAAfqB,KAAI,GAAAD,KAAA,CAAAnB,KAAA;IACd,IAAIqB,YAAY,CAACD,KAAI,EAAEJ,gBAAgB,CAAC,EAAE;MACzC;IACD;EACD;EAEAM,2BAA2B,CAACP,KAAK,CAAClB,MAAM,CAAC;AAC1C;AAEO,SAASwB,YAAYA,CAACD,MAAI,EAAEJ,gBAAgB,EAAE;EACpD,IAAMO,QAAQ,GAAGP,gBAAgB,CAACI,MAAI,CAAC;EACvC,IAAIG,QAAQ,KAAKC,SAAS,EAAE;IAC3B;IACA,IAAID,QAAQ,KAAKE,qCAAa,EAAE;MAC/B,MAAM,IAAIC,6BAAiB,CAAC,wBAAwB,CAAC;IACtD;IACA;IACA,IAAIH,QAAQ,GAAG,CAAC,EAAE;MACjB,MAAM,IAAIG,6BAAiB,CAAC,oBAAoB,CAAC;IAClD;IACA,OAAO,IAAI;EACZ;AACD;AAEO,SAASJ,2BAA2BA,CAACK,SAAS,EAAE;EACtD;EACA,MAAM,IAAID,6BAAiB,CAACC,SAAS,KAAK,CAAC,GAAG,SAAS,GAAG,oBAAoB,CAAC;AAChF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateLeadingBytes.test.js","names":["_mocha","require","_chai","_validateLeadingBytes","_interopRequireDefault","_InvalidInputError","obj","__esModule","describe","it","XLSX_FILE_FIRST_BYTES","expect","validateLeadingBytes","to","not","XLS_FILE_FIRST_BYTES","InvalidInputError","and","satisfy","error","have","property","NOT_A_ZIP_FILE_FIRST_BYTES","slice"],"sources":["../../../source/xlsx/file/validateLeadingBytes.test.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\nimport { describe, it } from 'mocha'\r\nimport { expect } from 'chai'\r\n\r\nimport validateLeadingBytes from './validateLeadingBytes.js'\r\n\r\nimport InvalidInputError from './InvalidInputError.js'\r\n\r\ndescribe('validateLeadingBytes', () => {\r\n\tit('should not throw when ZIP file signature is present', () => {\r\n\t\t// \"PK\\x03\\x04\" — a normal ZIP file signature.\r\n\t\tconst XLSX_FILE_FIRST_BYTES = [0x50, 0x4B, 0x03, 0x04]\r\n\t\texpect(() => validateLeadingBytes(XLSX_FILE_FIRST_BYTES)).to.not.throw()\r\n\t})\r\n\r\n\tit('should throw when it detects a legacy binary `.xls` file (CFB signature)', () => {\r\n\t\tconst XLS_FILE_FIRST_BYTES = [0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1]\r\n\t\texpect(() => validateLeadingBytes(XLS_FILE_FIRST_BYTES)).to.throw(InvalidInputError).and.satisfy((error) => {\r\n\t\t\texpect(error).to.have.property('name', 'InvalidInputError')\r\n\t\t\texpect(error).to.have.property('code', 'XLS_FILE_NOT_SUPPORTED')\r\n\t\t\t// Must return `true` for `satisfy()` to pass.\r\n\t\t\treturn true\r\n\t\t})\r\n\t})\r\n\r\n\tit('should throw when it encounters a non-ZIP file signature', () => {\r\n\t\tconst NOT_A_ZIP_FILE_FIRST_BYTES = [0x00, 0x01, 0x02, 0x03]\r\n\t\texpect(() => validateLeadingBytes(NOT_A_ZIP_FILE_FIRST_BYTES)).to.throw(InvalidInputError).and.satisfy((error) => {\r\n\t\t\texpect(error).to.have.property('name', 'InvalidInputError')\r\n\t\t\texpect(error).to.have.property('code', 'FILE_NOT_SUPPORTED')\r\n\t\t\t// Must return `true` for `satisfy()` to pass.\r\n\t\t\treturn true\r\n\t\t})\r\n\t})\r\n\r\n\tit('should throw when the input is shorter than the ZIP file signature', () => {\r\n\t\tconst XLSX_FILE_FIRST_BYTES = [0x50, 0x4B, 0x03, 0x04]\r\n\r\n\t\texpect(() => validateLeadingBytes(XLSX_FILE_FIRST_BYTES.slice(0, 0))).to.throw(InvalidInputError).and.satisfy((error) => {\r\n\t\t\texpect(error).to.have.property('name', 'InvalidInputError')\r\n\t\t\texpect(error).to.have.property('code', 'NO_DATA')\r\n\t\t\t// Must return `true` for `satisfy()` to pass.\r\n\t\t\treturn true\r\n\t\t})\r\n\r\n\t\texpect(() => validateLeadingBytes(XLSX_FILE_FIRST_BYTES.slice(0, 1))).to.throw(InvalidInputError).and.satisfy((error) => {\r\n\t\t\texpect(error).to.have.property('name', 'InvalidInputError')\r\n\t\t\texpect(error).to.have.property('code', 'FILE_NOT_SUPPORTED')\r\n\t\t\t// Must return `true` for `satisfy()` to pass.\r\n\t\t\treturn true\r\n\t\t})\r\n\r\n\t\texpect(() => validateLeadingBytes(XLSX_FILE_FIRST_BYTES.slice(0, 2))).to.not.throw()\r\n\t\texpect(() => validateLeadingBytes(XLSX_FILE_FIRST_BYTES.slice(0, 3))).to.not.throw()\r\n\t\texpect(() => validateLeadingBytes(XLSX_FILE_FIRST_BYTES.slice(0, 4))).to.not.throw()\r\n\t})\r\n})"],"mappings":";;AAGA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAEA,IAAAE,qBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,IAAAI,kBAAA,GAAAD,sBAAA,CAAAH,OAAA;AAAsD,SAAAG,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,gBAAAA,GAAA;AARtD;AACA;;AASA,IAAAE,eAAQ,EAAC,sBAAsB,EAAE,YAAM;EACtC,IAAAC,SAAE,EAAC,qDAAqD,EAAE,YAAM;IAC/D;IACA,IAAMC,qBAAqB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IACtD,IAAAC,YAAM,EAAC;MAAA,OAAM,IAAAC,gCAAoB,EAACF,qBAAqB,CAAC;IAAA,EAAC,CAACG,EAAE,CAACC,GAAG,SAAM,CAAC,CAAC;EACzE,CAAC,CAAC;EAEF,IAAAL,SAAE,EAAC,0EAA0E,EAAE,YAAM;IACpF,IAAMM,oBAAoB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAA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,EAAC,CAACV,EAAE,CAACC,GAAG,SAAM,CAAC,CAAC;IACpF,IAAAH,YAAM,EAAC;MAAA,OAAM,IAAAC,gCAAoB,EAACF,qBAAqB,CAACa,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAAA,EAAC,CAACV,EAAE,CAACC,GAAG,SAAM,CAAC,CAAC;EACrF,CAAC,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -3,10 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.IS_DATE_FORMAT_CACHE = exports.DATE_TEMPLATE_TOKENS = exports.DATE_FORMAT_SPECIFIC_LOCALE_PREFIX = exports.DATE_FORMAT_ALLOW_ANY_OTHER_TEXT_SUFFIX = void 0;
|
|
6
7
|
exports["default"] = isDateFormatCached;
|
|
7
|
-
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."); }
|
|
8
|
-
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); }
|
|
9
|
-
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; }
|
|
10
8
|
// On some date formats, there's a "[$-...]" prefix that locks the locale
|
|
11
9
|
// to be a specific one when formatting a date using this format.
|
|
12
10
|
//
|
|
@@ -19,7 +17,9 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
19
17
|
// * "[$-ru-RU]dd.mm.yyyy;@"
|
|
20
18
|
// * "[$-x-sysdate]dddd, mmmm dd, yyyy"
|
|
21
19
|
//
|
|
22
|
-
|
|
20
|
+
// This is exported only to be specified in `worker-f` dependencies.
|
|
21
|
+
//
|
|
22
|
+
var DATE_FORMAT_SPECIFIC_LOCALE_PREFIX = exports.DATE_FORMAT_SPECIFIC_LOCALE_PREFIX = /^\[\$-[^\]]+\]/;
|
|
23
23
|
|
|
24
24
|
// On some date formats, there's a ";@" suffix.
|
|
25
25
|
// It instructs the spreadsheet editor application to display any non-numeric
|
|
@@ -42,17 +42,18 @@ var DATE_FORMAT_SPECIFIC_LOCALE_PREFIX = /^\[\$-[^\]]+\]/;
|
|
|
42
42
|
// * "m/d/yyyy;@"
|
|
43
43
|
// * "[$-414]mmmm\ yyyy;@"
|
|
44
44
|
//
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
// This is exported only to be specified in `worker-f` dependencies.
|
|
46
|
+
//
|
|
47
|
+
var DATE_FORMAT_ALLOW_ANY_OTHER_TEXT_SUFFIX = exports.DATE_FORMAT_ALLOW_ANY_OTHER_TEXT_SUFFIX = /;@$/;
|
|
48
|
+
|
|
49
|
+
// This is exported only to be specified in `worker-f` dependencies.
|
|
50
|
+
//
|
|
51
|
+
var IS_DATE_FORMAT_CACHE = exports.IS_DATE_FORMAT_CACHE = {};
|
|
47
52
|
function isDateFormatCached(template) {
|
|
48
|
-
if (template in
|
|
49
|
-
return
|
|
53
|
+
if (template in IS_DATE_FORMAT_CACHE) {
|
|
54
|
+
return IS_DATE_FORMAT_CACHE[template];
|
|
50
55
|
}
|
|
51
|
-
|
|
52
|
-
CACHE[template] = result;
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
function isDateFormat(template) {
|
|
56
|
+
|
|
56
57
|
// Date format tokens could be in upper case or in lower case.
|
|
57
58
|
// There seems to be no single standard.
|
|
58
59
|
// So the template is lowercased first.
|
|
@@ -70,27 +71,31 @@ function isDateFormat(template) {
|
|
|
70
71
|
// Extract all alphabetic parts from what's left from the template string.
|
|
71
72
|
// Example: "mm/dd/yyyy" → ["mm", "dd", "yyyy"]
|
|
72
73
|
var tokens = template.split(/\W+/);
|
|
73
|
-
|
|
74
|
+
var result = tokens.length === 0
|
|
74
75
|
// If no alphabetic parts are present in what's left from the template string
|
|
75
76
|
// then it could be any kind of template such as a generic numeric template
|
|
76
77
|
// such as "$#,##0.00" currency template or "0.0%" percentage template.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
78
|
+
? false
|
|
79
|
+
// If a non-date-format-specific alphabetic substring is found,
|
|
80
|
+
// then it might be not necessarily a date format.
|
|
81
|
+
// In order to make a certain guess, all tokens have to represent viable parts of a date format.
|
|
82
|
+
: tokens.every(function (token) {
|
|
83
|
+
return DATE_TEMPLATE_TOKENS.indexOf(token) >= 0;
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Cache the result
|
|
87
|
+
IS_DATE_FORMAT_CACHE[template] = result;
|
|
88
|
+
|
|
89
|
+
// Return the result
|
|
90
|
+
return result;
|
|
89
91
|
}
|
|
90
92
|
|
|
91
93
|
// These tokens could be in upper case or in lower case.
|
|
92
94
|
// There seems to be no single standard, so using lower case.
|
|
93
|
-
|
|
95
|
+
//
|
|
96
|
+
// This is exported only to be specified in `worker-f` dependencies.
|
|
97
|
+
//
|
|
98
|
+
var DATE_TEMPLATE_TOKENS = exports.DATE_TEMPLATE_TOKENS = [
|
|
94
99
|
// Seconds (min two digits). Example: "05".
|
|
95
100
|
'ss',
|
|
96
101
|
// Minutes (min two digits). Example: "05". Could also be "Months". Weird.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isDateFormat.js","names":["DATE_FORMAT_SPECIFIC_LOCALE_PREFIX","DATE_FORMAT_ALLOW_ANY_OTHER_TEXT_SUFFIX","
|
|
1
|
+
{"version":3,"file":"isDateFormat.js","names":["DATE_FORMAT_SPECIFIC_LOCALE_PREFIX","exports","DATE_FORMAT_ALLOW_ANY_OTHER_TEXT_SUFFIX","IS_DATE_FORMAT_CACHE","isDateFormatCached","template","toLowerCase","replace","tokens","split","result","length","every","token","DATE_TEMPLATE_TOKENS","indexOf"],"sources":["../../source/xlsx/isDateFormat.js"],"sourcesContent":["// On some date formats, there's a \"[$-...]\" prefix that locks the locale\r\n// to be a specific one when formatting a date using this format.\r\n//\r\n// https://stackoverflow.com/questions/4730152/what-indicates-an-office-open-xml-cell-contains-a-date-time-value\r\n//\r\n// Format examples:\r\n//\r\n// * \"[$-404]e/m/d\"\r\n// * \"[$-414]mmmm\\ yyyy;@\"\r\n// * \"[$-ru-RU]dd.mm.yyyy;@\"\r\n// * \"[$-x-sysdate]dddd, mmmm dd, yyyy\"\r\n//\r\n// This is exported only to be specified in `worker-f` dependencies.\r\n//\r\nexport const DATE_FORMAT_SPECIFIC_LOCALE_PREFIX = /^\\[\\$-[^\\]]+\\]/\r\n\r\n// On some date formats, there's a \";@\" suffix.\r\n// It instructs the spreadsheet editor application to display any non-numeric\r\n// value as is instead of hiding it or something like that.\r\n//\r\n// For example, if one inputs \"Some text\" instead of a date in such cell,\r\n// it will still show \"Some text\" instead of an empty cell, even though\r\n// the value is strictly-speaking invalid.\r\n//\r\n// Specifically, \";\" means \"anything before this applies only to a numeric value,\r\n// while anything after it applies to a text value\". And a follow-up \"@\" means\r\n// \"for a text value, just output it as is\".\r\n//\r\n// It's not really clear why would anyone add such a feature to a format.\r\n// Perhaps it feels more \"user-friendly\" towards a non-\"tech-savvy\" user\r\n// of a spreadsheet editor application.\r\n//\r\n// Format examples:\r\n//\r\n// * \"m/d/yyyy;@\"\r\n// * \"[$-414]mmmm\\ yyyy;@\"\r\n//\r\n// This is exported only to be specified in `worker-f` dependencies.\r\n//\r\nexport const DATE_FORMAT_ALLOW_ANY_OTHER_TEXT_SUFFIX = /;@$/\r\n\r\n// This is exported only to be specified in `worker-f` dependencies.\r\n//\r\nexport const IS_DATE_FORMAT_CACHE = {}\r\n\r\nexport default function isDateFormatCached(template) {\r\n\tif (template in IS_DATE_FORMAT_CACHE) {\r\n\t\treturn IS_DATE_FORMAT_CACHE[template]\r\n\t}\r\n\r\n // Date format tokens could be in upper case or in lower case.\r\n // There seems to be no single standard.\r\n // So the template is lowercased first.\r\n template = template.toLowerCase()\r\n\r\n // On some date formats, there's an \"[$-...]\" prefix.\r\n // It forces a specific locale to be used when formatting a date.\r\n template = template.replace(DATE_FORMAT_SPECIFIC_LOCALE_PREFIX, '')\r\n\r\n // On some date formats, there's an \";@\" suffix.\r\n // It's not clear why would anyone need it in a date format template.\r\n\t// Still, because it occurs there, it should be stripped.\r\n template = template.replace(DATE_FORMAT_ALLOW_ANY_OTHER_TEXT_SUFFIX, '')\r\n\r\n // Extract all alphabetic parts from what's left from the template string.\r\n // Example: \"mm/dd/yyyy\" → [\"mm\", \"dd\", \"yyyy\"]\r\n const tokens = template.split(/\\W+/)\r\n\r\n const result = tokens.length === 0\r\n // If no alphabetic parts are present in what's left from the template string\r\n // then it could be any kind of template such as a generic numeric template\r\n // such as \"$#,##0.00\" currency template or \"0.0%\" percentage template.\r\n ? false\r\n // If a non-date-format-specific alphabetic substring is found,\r\n // then it might be not necessarily a date format.\r\n // In order to make a certain guess, all tokens have to represent viable parts of a date format.\r\n : tokens.every(token => DATE_TEMPLATE_TOKENS.indexOf(token) >= 0)\r\n\r\n // Cache the result\r\n IS_DATE_FORMAT_CACHE[template] = result\r\n\r\n // Return the result\r\n return result\r\n}\r\n\r\n// These tokens could be in upper case or in lower case.\r\n// There seems to be no single standard, so using lower case.\r\n//\r\n// This is exported only to be specified in `worker-f` dependencies.\r\n//\r\nexport const DATE_TEMPLATE_TOKENS = [\r\n // Seconds (min two digits). Example: \"05\".\r\n 'ss',\r\n // Minutes (min two digits). Example: \"05\". Could also be \"Months\". Weird.\r\n 'mm',\r\n // Hours. Example: \"1\".\r\n 'h',\r\n // Hours (min two digits). Example: \"01\".\r\n 'hh',\r\n // \"AM\" part of \"AM/PM\". Lowercased just in case.\r\n 'am',\r\n // \"PM\" part of \"AM/PM\". Lowercased just in case.\r\n 'pm',\r\n // Day. Example: \"1\"\r\n 'd',\r\n // Day (min two digits). Example: \"01\"\r\n 'dd',\r\n // Month (numeric). Example: \"1\".\r\n 'm',\r\n // Month (numeric, min two digits). Example: \"01\". Could also be \"Minutes\". Weird.\r\n 'mm',\r\n // Month (shortened month name). Example: \"Jan\".\r\n 'mmm',\r\n // Month (full month name). Example: \"January\".\r\n 'mmmm',\r\n // Two-digit year. Example: \"20\".\r\n 'yy',\r\n // Full year. Example: \"2020\".\r\n 'yyyy',\r\n\r\n // I don't have any idea what \"e\" means.\r\n // It's used in \"built-in\" XLSX formats:\r\n // * 27 '[$-404]e/m/d';\r\n // * 36 '[$-404]e/m/d';\r\n // * 50 '[$-404]e/m/d';\r\n // * 57 '[$-404]e/m/d';\r\n 'e'\r\n]"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMA,kCAAkC,GAAAC,OAAA,CAAAD,kCAAA,GAAG,gBAAgB;;AAElE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAME,uCAAuC,GAAAD,OAAA,CAAAC,uCAAA,GAAG,KAAK;;AAE5D;AACA;AACO,IAAMC,oBAAoB,GAAAF,OAAA,CAAAE,oBAAA,GAAG,CAAC,CAAC;AAEvB,SA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