read-excel-file 5.5.2 → 5.6.0
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/README.md +14 -3
- package/bundle/read-excel-file.min.js +1 -1
- package/bundle/read-excel-file.min.js.map +1 -1
- package/commonjs/read/readXlsxFileNode.test.js.map +1 -1
- package/commonjs/read/schema/convertToJson.js +20 -215
- package/commonjs/read/schema/convertToJson.js.map +1 -1
- package/commonjs/read/unpackXlsxFileBrowser.js +12 -2
- package/commonjs/read/unpackXlsxFileBrowser.js.map +1 -1
- package/commonjs/types/Boolean.js +19 -0
- package/commonjs/types/Boolean.js.map +1 -0
- package/commonjs/types/Date.js +48 -0
- package/commonjs/types/Date.js.map +1 -0
- package/commonjs/types/Email.js +15 -1
- package/commonjs/types/Email.js.map +1 -1
- package/commonjs/types/Integer.js +15 -1
- package/commonjs/types/Integer.js.map +1 -1
- package/commonjs/types/InvalidError.js +55 -0
- package/commonjs/types/InvalidError.js.map +1 -0
- package/commonjs/types/Number.js +53 -0
- package/commonjs/types/Number.js.map +1 -0
- package/commonjs/types/String.js +48 -0
- package/commonjs/types/String.js.map +1 -0
- package/commonjs/types/URL.js +15 -1
- package/commonjs/types/URL.js.map +1 -1
- package/index.d.ts +1 -1
- package/modules/read/readXlsxFileNode.test.js.map +1 -1
- package/modules/read/schema/convertToJson.js +20 -211
- package/modules/read/schema/convertToJson.js.map +1 -1
- package/modules/read/unpackXlsxFileBrowser.js +11 -2
- package/modules/read/unpackXlsxFileBrowser.js.map +1 -1
- package/modules/types/Boolean.js +9 -0
- package/modules/types/Boolean.js.map +1 -0
- package/modules/types/Date.js +37 -0
- package/modules/types/Date.js.map +1 -0
- package/modules/types/Email.js +12 -1
- package/modules/types/Email.js.map +1 -1
- package/modules/types/Integer.js +11 -1
- package/modules/types/Integer.js.map +1 -1
- package/modules/types/InvalidError.js +48 -0
- package/modules/types/InvalidError.js.map +1 -0
- package/modules/types/Number.js +43 -0
- package/modules/types/Number.js.map +1 -0
- package/modules/types/String.js +38 -0
- package/modules/types/String.js.map +1 -0
- package/modules/types/URL.js +12 -1
- package/modules/types/URL.js.map +1 -1
- package/package.json +1 -1
- package/web-worker/index.d.ts +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
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, descriptor.key, descriptor); } }
|
|
11
|
+
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
|
|
14
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
|
+
|
|
16
|
+
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); }
|
|
17
|
+
|
|
18
|
+
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); }; }
|
|
19
|
+
|
|
20
|
+
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); }
|
|
21
|
+
|
|
22
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
23
|
+
|
|
24
|
+
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); }
|
|
25
|
+
|
|
26
|
+
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } 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); }
|
|
27
|
+
|
|
28
|
+
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; } }
|
|
29
|
+
|
|
30
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
31
|
+
|
|
32
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
33
|
+
|
|
34
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
35
|
+
|
|
36
|
+
var InvalidError = /*#__PURE__*/function (_Error) {
|
|
37
|
+
_inherits(InvalidError, _Error);
|
|
38
|
+
|
|
39
|
+
var _super = _createSuper(InvalidError);
|
|
40
|
+
|
|
41
|
+
function InvalidError(reason) {
|
|
42
|
+
var _this;
|
|
43
|
+
|
|
44
|
+
_classCallCheck(this, InvalidError);
|
|
45
|
+
|
|
46
|
+
_this = _super.call(this, 'invalid');
|
|
47
|
+
_this.reason = reason;
|
|
48
|
+
return _this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return _createClass(InvalidError);
|
|
52
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
53
|
+
|
|
54
|
+
exports["default"] = InvalidError;
|
|
55
|
+
//# sourceMappingURL=InvalidError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InvalidError.js","names":["InvalidError","reason","Error"],"sources":["../../source/types/InvalidError.js"],"sourcesContent":["export default class InvalidError extends Error {\r\n constructor(reason) {\r\n super('invalid')\r\n this.reason = reason\r\n }\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAqBA,Y;;;;;EACnB,sBAAYC,MAAZ,EAAoB;IAAA;;IAAA;;IAClB,0BAAM,SAAN;IACA,MAAKA,MAAL,GAAcA,MAAd;IAFkB;EAGnB;;;iCAJuCC,K"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = NumberType;
|
|
7
|
+
|
|
8
|
+
var _InvalidError = _interopRequireDefault(require("./InvalidError.js"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
|
|
12
|
+
function NumberType(value) {
|
|
13
|
+
// An XLSX file editing software might not always correctly
|
|
14
|
+
// detect numeric values in string-type cells. Users won't bother
|
|
15
|
+
// manually selecting a cell type, so the editing software has to guess
|
|
16
|
+
// based on the user's input. One can assume that such auto-detection
|
|
17
|
+
// might not always work.
|
|
18
|
+
//
|
|
19
|
+
// So, if a cell is supposed to be a numeric one, convert a string value to a number.
|
|
20
|
+
//
|
|
21
|
+
if (typeof value === 'string') {
|
|
22
|
+
var stringifiedValue = value;
|
|
23
|
+
value = Number(value);
|
|
24
|
+
|
|
25
|
+
if (String(value) !== stringifiedValue) {
|
|
26
|
+
throw new _InvalidError["default"]('not_a_number');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (typeof value !== 'number') {
|
|
31
|
+
throw new _InvalidError["default"]('not_a_number');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (isNaN(value)) {
|
|
35
|
+
throw new _InvalidError["default"]('invalid_number');
|
|
36
|
+
} // At this point, `value` can only be a number.
|
|
37
|
+
//
|
|
38
|
+
// The global `isFinite()` function filters out:
|
|
39
|
+
// * NaN
|
|
40
|
+
// * -Infinity
|
|
41
|
+
// * Infinity
|
|
42
|
+
//
|
|
43
|
+
// All other values pass (including non-numbers).
|
|
44
|
+
//
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if (!isFinite(value)) {
|
|
48
|
+
throw new _InvalidError["default"]('out_of_bounds');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=Number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Number.js","names":["NumberType","value","stringifiedValue","Number","String","InvalidError","isNaN","isFinite"],"sources":["../../source/types/Number.js"],"sourcesContent":["import InvalidError from './InvalidError.js'\r\n\r\nexport default function NumberType(value) {\r\n // An XLSX file editing software might not always correctly\r\n // detect numeric values in string-type cells. Users won't bother\r\n // manually selecting a cell type, so the editing software has to guess\r\n // based on the user's input. One can assume that such auto-detection\r\n // might not always work.\r\n //\r\n // So, if a cell is supposed to be a numeric one, convert a string value to a number.\r\n //\r\n if (typeof value === 'string') {\r\n const stringifiedValue = value\r\n value = Number(value)\r\n if (String(value) !== stringifiedValue) {\r\n throw new InvalidError('not_a_number')\r\n }\r\n }\r\n if (typeof value !== 'number') {\r\n throw new InvalidError('not_a_number')\r\n }\r\n if (isNaN(value)) {\r\n throw new InvalidError('invalid_number')\r\n }\r\n // At this point, `value` can only be a number.\r\n //\r\n // The global `isFinite()` function filters out:\r\n // * NaN\r\n // * -Infinity\r\n // * Infinity\r\n //\r\n // All other values pass (including non-numbers).\r\n //\r\n if (!isFinite(value)) {\r\n throw new InvalidError('out_of_bounds')\r\n }\r\n return value\r\n}"],"mappings":";;;;;;;AAAA;;;;AAEe,SAASA,UAAT,CAAoBC,KAApB,EAA2B;EACxC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;IAC7B,IAAMC,gBAAgB,GAAGD,KAAzB;IACAA,KAAK,GAAGE,MAAM,CAACF,KAAD,CAAd;;IACA,IAAIG,MAAM,CAACH,KAAD,CAAN,KAAkBC,gBAAtB,EAAwC;MACtC,MAAM,IAAIG,wBAAJ,CAAiB,cAAjB,CAAN;IACD;EACF;;EACD,IAAI,OAAOJ,KAAP,KAAiB,QAArB,EAA+B;IAC7B,MAAM,IAAII,wBAAJ,CAAiB,cAAjB,CAAN;EACD;;EACD,IAAIC,KAAK,CAACL,KAAD,CAAT,EAAkB;IAChB,MAAM,IAAII,wBAAJ,CAAiB,gBAAjB,CAAN;EACD,CArBuC,CAsBxC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;EACA,IAAI,CAACE,QAAQ,CAACN,KAAD,CAAb,EAAsB;IACpB,MAAM,IAAII,wBAAJ,CAAiB,eAAjB,CAAN;EACD;;EACD,OAAOJ,KAAP;AACD"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports["default"] = StringType;
|
|
7
|
+
|
|
8
|
+
var _InvalidError = _interopRequireDefault(require("./InvalidError.js"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
|
+
|
|
12
|
+
function StringType(value) {
|
|
13
|
+
if (typeof value === 'string') {
|
|
14
|
+
return value;
|
|
15
|
+
} // Excel tends to perform a forced automatic convertion of string-type values
|
|
16
|
+
// to number-type ones when the user has input them. Otherwise, users wouldn't
|
|
17
|
+
// be able to perform formula calculations on those cell values because users
|
|
18
|
+
// won't bother manually choosing a "numeric" cell type for each cell, and
|
|
19
|
+
// even if they did, choosing a "numeric" cell type every time wouldn't be an
|
|
20
|
+
// acceptable "user experience".
|
|
21
|
+
//
|
|
22
|
+
// So, if a cell value is supposed to be a string and Excel has automatically
|
|
23
|
+
// converted it to a number, perform a backwards conversion.
|
|
24
|
+
//
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if (typeof value === 'number') {
|
|
28
|
+
if (isNaN(value)) {
|
|
29
|
+
throw new _InvalidError["default"]('invalid_number');
|
|
30
|
+
} // The global `isFinite()` function filters out:
|
|
31
|
+
// * NaN
|
|
32
|
+
// * -Infinity
|
|
33
|
+
// * Infinity
|
|
34
|
+
//
|
|
35
|
+
// All other values pass (including non-numbers).
|
|
36
|
+
//
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if (!isFinite(value)) {
|
|
40
|
+
throw new _InvalidError["default"]('out_of_bounds');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return String(value);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
throw new _InvalidError["default"]('not_a_string');
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=String.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"String.js","names":["StringType","value","isNaN","InvalidError","isFinite","String"],"sources":["../../source/types/String.js"],"sourcesContent":["import InvalidError from './InvalidError.js'\r\n\r\nexport default function StringType(value) {\r\n if (typeof value === 'string') {\r\n return value\r\n }\r\n // Excel tends to perform a forced automatic convertion of string-type values\r\n // to number-type ones when the user has input them. Otherwise, users wouldn't\r\n // be able to perform formula calculations on those cell values because users\r\n // won't bother manually choosing a \"numeric\" cell type for each cell, and\r\n // even if they did, choosing a \"numeric\" cell type every time wouldn't be an\r\n // acceptable \"user experience\".\r\n //\r\n // So, if a cell value is supposed to be a string and Excel has automatically\r\n // converted it to a number, perform a backwards conversion.\r\n //\r\n if (typeof value === 'number') {\r\n if (isNaN(value)) {\r\n throw new InvalidError('invalid_number')\r\n }\r\n // The global `isFinite()` function filters out:\r\n // * NaN\r\n // * -Infinity\r\n // * Infinity\r\n //\r\n // All other values pass (including non-numbers).\r\n //\r\n if (!isFinite(value)) {\r\n throw new InvalidError('out_of_bounds')\r\n }\r\n return String(value)\r\n }\r\n throw new InvalidError('not_a_string')\r\n}"],"mappings":";;;;;;;AAAA;;;;AAEe,SAASA,UAAT,CAAoBC,KAApB,EAA2B;EACxC,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;IAC7B,OAAOA,KAAP;EACD,CAHuC,CAIxC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;EACA,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;IAC7B,IAAIC,KAAK,CAACD,KAAD,CAAT,EAAkB;MAChB,MAAM,IAAIE,wBAAJ,CAAiB,gBAAjB,CAAN;IACD,CAH4B,CAI7B;IACA;IACA;IACA;IACA;IACA;IACA;;;IACA,IAAI,CAACC,QAAQ,CAACH,KAAD,CAAb,EAAsB;MACpB,MAAM,IAAIE,wBAAJ,CAAiB,eAAjB,CAAN;IACD;;IACD,OAAOE,MAAM,CAACJ,KAAD,CAAb;EACD;;EACD,MAAM,IAAIE,wBAAJ,CAAiB,cAAjB,CAAN;AACD"}
|
package/commonjs/types/URL.js
CHANGED
|
@@ -6,7 +6,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports["default"] = URL;
|
|
7
7
|
exports.isURL = isURL;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
var _InvalidError = _interopRequireDefault(require("./InvalidError.js"));
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
|
+
|
|
13
|
+
function URL(value) {
|
|
14
|
+
if (typeof value === 'string') {
|
|
15
|
+
if (isURL(value)) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
throw new _InvalidError["default"]('not_a_url');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
throw new _InvalidError["default"]('not_a_string');
|
|
23
|
+
} // URL regexp explanation:
|
|
10
24
|
//
|
|
11
25
|
// /^
|
|
12
26
|
//
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"URL.js","names":["URL","
|
|
1
|
+
{"version":3,"file":"URL.js","names":["URL","value","isURL","InvalidError","regexp","test"],"sources":["../../source/types/URL.js"],"sourcesContent":["import InvalidError from './InvalidError.js'\r\n\r\nexport default function URL(value) {\r\n if (typeof value === 'string') {\r\n if (isURL(value)) {\r\n return value\r\n }\r\n throw new InvalidError('not_a_url')\r\n }\r\n throw new InvalidError('not_a_string')\r\n}\r\n\r\n// URL regexp explanation:\r\n//\r\n// /^\r\n//\r\n// \t(?:\r\n// \t // Matches optional \"http(s):\" or \"ftp:\":\r\n// \t\t(?:\r\n// \t\t\t(?:https?|ftp):\r\n// \t\t)?\r\n//\r\n// \t // Matches \"//\" (required):\r\n// \t\t\\/\\/\r\n// \t)\r\n//\r\n// \t// Matches a valid non-local IP address:\r\n// \t(?:\r\n// \t\t(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])\r\n// \t\t(?:\r\n// \t\t\t\\.\r\n// \t\t\t(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])\r\n// \t\t){2}\r\n// \t\t(?:\r\n// \t\t\t\\.\r\n// \t\t\t(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4])\r\n// \t\t)\r\n//\r\n// \t // Or,\r\n// \t\t|\r\n//\r\n// \t // Matches an alpha-numeric domain name.\r\n// \t\t(?:\r\n// \t\t\t(?:\r\n// \t\t\t\t[a-z0-9\\u00a1-\\uffff]\r\n// \t\t\t\t[a-z0-9\\u00a1-\\uffff_-]{0,62}\r\n// \t\t\t)?\r\n// \t\t\t[a-z0-9\\u00a1-\\uffff]\r\n// \t\t\t\\.\r\n// \t\t)*\r\n// \t\t(?:\r\n// \t // Domain zone: \"com\", \"net\", etc (required):\r\n// \t\t\t[a-z\\u00a1-\\uffff]{2,}\r\n// \t\t)\r\n// \t)\r\n//\r\n// \t// Matches a colon and a port number:\r\n// \t(?::\\d{2,5})?\r\n//\r\n// \t// Matches everything after the \"origin\":\r\n// \t// * pathname\r\n// \t// * query\r\n// \t// * hash\r\n// \t(?:[/?#]\\S*)?\r\n//\r\n// $/i\r\n\r\nconst regexp = /^(?:(?:(?:https?|ftp):)?\\/\\/)(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u00a1-\\uffff][a-z0-9\\u00a1-\\uffff_-]{0,62})?[a-z0-9\\u00a1-\\uffff]\\.)*(?:[a-z\\u00a1-\\uffff]{2,}))(?::\\d{2,5})?(?:[/?#]\\S*)?$/i\r\n\r\n// https://stackoverflow.com/questions/8667070/javascript-regular-expression-to-validate-url\r\nexport function isURL(value) {\r\n\treturn regexp.test(value)\r\n}"],"mappings":";;;;;;;;AAAA;;;;AAEe,SAASA,GAAT,CAAaC,KAAb,EAAoB;EACjC,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;IAC7B,IAAIC,KAAK,CAACD,KAAD,CAAT,EAAkB;MAChB,OAAOA,KAAP;IACD;;IACD,MAAM,IAAIE,wBAAJ,CAAiB,WAAjB,CAAN;EACD;;EACD,MAAM,IAAIA,wBAAJ,CAAiB,cAAjB,CAAN;AACD,C,CAED;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAEA,IAAMC,MAAM,GAAG,+RAAf,C,CAEA;;AACO,SAASF,KAAT,CAAeD,KAAf,EAAsB;EAC5B,OAAOG,MAAM,CAACC,IAAP,CAAYJ,KAAZ,CAAP;AACA"}
|
package/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export {
|
|
|
17
17
|
|
|
18
18
|
export function parseExcelDate(excelSerialDate: number) : typeof Date;
|
|
19
19
|
|
|
20
|
-
type Input = File | ArrayBuffer;
|
|
20
|
+
type Input = File | Blob | ArrayBuffer;
|
|
21
21
|
|
|
22
22
|
export function readXlsxFile<T extends object>(input: Input, options: ParseWithSchemaOptions<T>) : Promise<ParsedObjectsResult<T>>;
|
|
23
23
|
export function readXlsxFile<T extends object>(input: Input, options: ParseWithMapOptions) : Promise<ParsedObjectsResult<T>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readXlsxFileNode.test.js","names":["path","readXlsxFileNode","describe","it","schema","prop","type","Date","Number","required","Boolean","String","parse","value","rowMap","resolve","then","rows","date","getTime","should","deep","equal","convertToUTCTimezone","numberOfStudents","course","isFree","cost","title","contact","map","errors","getTimezoneOffset"],"sources":["../../source/read/readXlsxFileNode.test.js"],"sourcesContent":["import path from 'path'\r\n\r\nimport readXlsxFileNode from './readXlsxFileNode.js'\r\n\r\ndescribe('readXlsxFileNode', () => {\r\n\tit('should read *.xlsx file on Node.js and parse it to JSON', () => {\r\n\t\tconst schema = {\r\n\t\t\t'START DATE': {\r\n\t\t\t\tprop: 'date',\r\n\t\t\t\ttype: Date\r\n\t\t\t},\r\n\t\t\t'NUMBER OF STUDENTS': {\r\n\t\t\t\tprop: 'numberOfStudents',\r\n\t\t\t\ttype: Number,\r\n\t\t\t\trequired: true\r\n\t\t\t},\r\n\t\t\t'COURSE': {\r\n\t\t\t\tprop: 'course',\r\n\t\t\t\ttype: {\r\n\t\t\t\t\t'IS FREE': {\r\n\t\t\t\t\t\tprop: 'isFree',\r\n\t\t\t\t\t\ttype: Boolean\r\n\t\t\t\t\t\t// Excel
|
|
1
|
+
{"version":3,"file":"readXlsxFileNode.test.js","names":["path","readXlsxFileNode","describe","it","schema","prop","type","Date","Number","required","Boolean","String","parse","value","rowMap","resolve","then","rows","date","getTime","should","deep","equal","convertToUTCTimezone","numberOfStudents","course","isFree","cost","title","contact","map","errors","getTimezoneOffset"],"sources":["../../source/read/readXlsxFileNode.test.js"],"sourcesContent":["import path from 'path'\r\n\r\nimport readXlsxFileNode from './readXlsxFileNode.js'\r\n\r\ndescribe('readXlsxFileNode', () => {\r\n\tit('should read *.xlsx file on Node.js and parse it to JSON', () => {\r\n\t\tconst schema = {\r\n\t\t\t'START DATE': {\r\n\t\t\t\tprop: 'date',\r\n\t\t\t\ttype: Date\r\n\t\t\t},\r\n\t\t\t'NUMBER OF STUDENTS': {\r\n\t\t\t\tprop: 'numberOfStudents',\r\n\t\t\t\ttype: Number,\r\n\t\t\t\trequired: true\r\n\t\t\t},\r\n\t\t\t'COURSE': {\r\n\t\t\t\tprop: 'course',\r\n\t\t\t\ttype: {\r\n\t\t\t\t\t'IS FREE': {\r\n\t\t\t\t\t\tprop: 'isFree',\r\n\t\t\t\t\t\ttype: Boolean\r\n\t\t\t\t\t\t// Excel stores booleans as numbers:\r\n\t\t\t\t\t\t// `1` is `true` and `0` is `false`.\r\n\t\t\t\t\t\t// Such numbers are parsed into booleans.\r\n\t\t\t\t\t},\r\n\t\t\t\t\t'COST': {\r\n\t\t\t\t\t\tprop: 'cost',\r\n\t\t\t\t\t\ttype: Number\r\n\t\t\t\t\t},\r\n\t\t\t\t\t'COURSE TITLE': {\r\n\t\t\t\t\t\tprop: 'title',\r\n\t\t\t\t\t\ttype: String\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t},\r\n\t\t\t'CONTACT': {\r\n\t\t\t\tprop: 'contact',\r\n\t\t\t\trequired: true,\r\n\t\t\t\tparse(value) {\r\n\t\t\t\t\treturn '+11234567890'\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tconst rowMap = []\r\n\r\n\t\treturn readXlsxFileNode(path.resolve('./test/spreadsheets/course.xlsx'), { schema, rowMap }).then(({ rows }) => {\r\n\t\t\trows[0].date = rows[0].date.getTime()\r\n\t\t\trows.should.deep.equal([{\r\n\t\t\t\tdate: convertToUTCTimezone(new Date(2018, 2, 24)).getTime(),\r\n\t\t\t\tnumberOfStudents: 123,\r\n\t\t\t\tcourse: {\r\n\t\t\t\t\tisFree: false,\r\n\t\t\t\t\tcost: 210.45,\r\n\t\t\t\t\ttitle: 'Chemistry'\r\n\t\t\t\t},\r\n\t\t\t\tcontact: '+11234567890'\r\n\t\t\t}])\r\n\t\t\trowMap.should.deep.equal([0, 1])\r\n\t\t})\r\n\t})\r\n\r\n\tit('should read *.xlsx file on Node.js and map it to JSON', () => {\r\n\t\tconst map = {\r\n\t\t\t'START DATE': 'date',\r\n\t\t\t'NUMBER OF STUDENTS': 'numberOfStudents',\r\n\t\t\t'COURSE': {\r\n\t\t\t\t'course': {\r\n\t\t\t\t\t'IS FREE': 'isFree',\r\n\t\t\t\t\t'COST': 'cost',\r\n\t\t\t\t\t'COURSE TITLE': 'title'\r\n\t\t\t\t}\r\n\t\t\t},\r\n\t\t\t'CONTACT': 'contact'\r\n\t\t}\r\n\r\n\t\tconst rowMap = []\r\n\r\n\t\treturn readXlsxFileNode(path.resolve('./test/spreadsheets/course.xlsx'), { map, rowMap }).then(({ rows, errors }) => {\r\n\t\t\terrors.should.deep.equal([])\r\n\t\t\trows[0].date = rows[0].date.getTime()\r\n\t\t\trows.should.deep.equal([{\r\n\t\t\t\tdate: convertToUTCTimezone(new Date(2018, 2, 24)).getTime(),\r\n\t\t\t\tnumberOfStudents: 123,\r\n\t\t\t\tcourse: {\r\n\t\t\t\t\tisFree: false,\r\n\t\t\t\t\tcost: 210.45,\r\n\t\t\t\t\ttitle: 'Chemistry'\r\n\t\t\t\t},\r\n\t\t\t\tcontact: '(123) 456-7890'\r\n\t\t\t}])\r\n\t\t\trowMap.should.deep.equal([0, 1])\r\n\t\t})\r\n\t})\r\n})\r\n\r\n// Converts timezone to UTC while preserving the same time\r\nfunction convertToUTCTimezone(date) {\r\n\t// Doesn't account for leap seconds but I guess that's ok\r\n\t// given that javascript's own `Date()` does not either.\r\n\t// https://www.timeanddate.com/time/leap-seconds-background.html\r\n\t//\r\n\t// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset\r\n\t//\r\n\treturn new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000)\r\n}\r\n"],"mappings":"AAAA,OAAOA,IAAP,MAAiB,MAAjB;AAEA,OAAOC,gBAAP,MAA6B,uBAA7B;AAEAC,QAAQ,CAAC,kBAAD,EAAqB,YAAM;EAClCC,EAAE,CAA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AQvBC,OAAO,EAAE;MARc,CAAD,CAAvB;MAUAf,MAAM,CAACM,MAAP,CAAcC,IAAd,CAAmBC,KAAnB,CAAyB,CAAC,CAAD,EAAI,CAAJ,CAAzB;IACA,CAdM,CAAP;EAeA,CA/BC,CAAF;AAgCA,CA3FO,CAAR,C,CA6FA;;AACA,SAASC,oBAAT,CAA8BL,IAA9B,EAAoC;EACnC;EACA;EACA;EACA;EACA;EACA;EACA,OAAO,IAAIX,IAAJ,CAASW,IAAI,CAACC,OAAL,KAAiBD,IAAI,CAACc,iBAAL,KAA2B,EAA3B,GAAgC,IAA1D,CAAP;AACA"}
|
|
@@ -20,10 +20,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
20
20
|
|
|
21
21
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
22
22
|
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import
|
|
23
|
+
import NumberType from '../../types/Number.js';
|
|
24
|
+
import StringType from '../../types/String.js';
|
|
25
|
+
import BooleanType from '../../types/Boolean.js';
|
|
26
|
+
import DateType from '../../types/Date.js';
|
|
27
27
|
var DEFAULT_OPTIONS = {
|
|
28
28
|
isColumnOriented: false
|
|
29
29
|
};
|
|
@@ -256,9 +256,15 @@ function parseCustomValue(value, parse) {
|
|
|
256
256
|
value: value
|
|
257
257
|
};
|
|
258
258
|
} catch (error) {
|
|
259
|
-
|
|
259
|
+
var result = {
|
|
260
260
|
error: error.message
|
|
261
261
|
};
|
|
262
|
+
|
|
263
|
+
if (error.reason) {
|
|
264
|
+
result.reason = error.reason;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return result;
|
|
262
268
|
}
|
|
263
269
|
}
|
|
264
270
|
/**
|
|
@@ -272,224 +278,27 @@ function parseCustomValue(value, parse) {
|
|
|
272
278
|
function parseValueOfType(value, type, options) {
|
|
273
279
|
switch (type) {
|
|
274
280
|
case String:
|
|
275
|
-
|
|
276
|
-
return {
|
|
277
|
-
value: value
|
|
278
|
-
};
|
|
279
|
-
} // Excel tends to perform a forced automatic convertion of string-type values
|
|
280
|
-
// to number-type ones when the user has input them. Otherwise, users wouldn't
|
|
281
|
-
// be able to perform formula calculations on those cell values because users
|
|
282
|
-
// won't bother manually choosing a "numeric" cell type for each cell, and
|
|
283
|
-
// even if they did, choosing a "numeric" cell type every time wouldn't be an
|
|
284
|
-
// acceptable "user experience".
|
|
285
|
-
//
|
|
286
|
-
// So, if a cell value is supposed to be a string and Excel has automatically
|
|
287
|
-
// converted it to a number, perform a backwards conversion.
|
|
288
|
-
//
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
if (typeof value === 'number') {
|
|
292
|
-
if (isNaN(value)) {
|
|
293
|
-
return {
|
|
294
|
-
error: 'invalid',
|
|
295
|
-
reason: 'invalid_number'
|
|
296
|
-
};
|
|
297
|
-
} // The global `isFinite()` function filters out:
|
|
298
|
-
// * NaN
|
|
299
|
-
// * -Infinity
|
|
300
|
-
// * Infinity
|
|
301
|
-
//
|
|
302
|
-
// All other values pass (including non-numbers).
|
|
303
|
-
//
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if (!isFinite(value)) {
|
|
307
|
-
return {
|
|
308
|
-
error: 'invalid',
|
|
309
|
-
reason: 'out_of_bounds'
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
return {
|
|
314
|
-
value: String(value)
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return {
|
|
319
|
-
error: 'invalid',
|
|
320
|
-
reason: 'not_a_string'
|
|
321
|
-
};
|
|
281
|
+
return parseCustomValue(value, StringType);
|
|
322
282
|
|
|
323
283
|
case Number:
|
|
324
|
-
|
|
325
|
-
// An XLSX file editing software might not always correctly
|
|
326
|
-
// detect numeric values in string-type cells. Users won't bother
|
|
327
|
-
// manually selecting a cell type, so the editing software has to guess
|
|
328
|
-
// based on the user's input. One can assume that such auto-detection
|
|
329
|
-
// might not always work.
|
|
330
|
-
//
|
|
331
|
-
// So, if a cell is supposed to be a numeric one, convert a string value to a number.
|
|
332
|
-
//
|
|
333
|
-
if (typeof value === 'string') {
|
|
334
|
-
var stringifiedValue = value;
|
|
335
|
-
value = Number(value);
|
|
336
|
-
|
|
337
|
-
if (String(value) !== stringifiedValue) {
|
|
338
|
-
return {
|
|
339
|
-
error: 'invalid',
|
|
340
|
-
reason: 'not_a_number'
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
if (typeof value !== 'number') {
|
|
346
|
-
return {
|
|
347
|
-
error: 'invalid',
|
|
348
|
-
reason: 'not_a_number'
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
if (isNaN(value)) {
|
|
353
|
-
return {
|
|
354
|
-
error: 'invalid',
|
|
355
|
-
reason: 'invalid_number'
|
|
356
|
-
};
|
|
357
|
-
} // At this point, `value` can only be a number.
|
|
358
|
-
//
|
|
359
|
-
// The global `isFinite()` function filters out:
|
|
360
|
-
// * NaN
|
|
361
|
-
// * -Infinity
|
|
362
|
-
// * Infinity
|
|
363
|
-
//
|
|
364
|
-
// All other values pass (including non-numbers).
|
|
365
|
-
//
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
if (!isFinite(value)) {
|
|
369
|
-
return {
|
|
370
|
-
error: 'invalid',
|
|
371
|
-
reason: 'out_of_bounds'
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (type === Integer && !isInteger(value)) {
|
|
376
|
-
return {
|
|
377
|
-
error: 'invalid',
|
|
378
|
-
reason: 'not_an_integer'
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
return {
|
|
383
|
-
value: value
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
case URL:
|
|
387
|
-
if (typeof value === 'string') {
|
|
388
|
-
if (isURL(value)) {
|
|
389
|
-
return {
|
|
390
|
-
value: value
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
return {
|
|
395
|
-
error: 'invalid',
|
|
396
|
-
reason: 'not_a_url'
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
return {
|
|
401
|
-
error: 'invalid',
|
|
402
|
-
reason: 'not_a_string'
|
|
403
|
-
};
|
|
404
|
-
|
|
405
|
-
case Email:
|
|
406
|
-
if (typeof value === 'string') {
|
|
407
|
-
if (isEmail(value)) {
|
|
408
|
-
return {
|
|
409
|
-
value: value
|
|
410
|
-
};
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
return {
|
|
414
|
-
error: 'invalid',
|
|
415
|
-
reason: 'not_an_email'
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
return {
|
|
420
|
-
error: 'invalid',
|
|
421
|
-
reason: 'not_a_string'
|
|
422
|
-
};
|
|
284
|
+
return parseCustomValue(value, NumberType);
|
|
423
285
|
|
|
424
286
|
case Date:
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
return {
|
|
431
|
-
error: 'invalid',
|
|
432
|
-
reason: 'out_of_bounds'
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
return {
|
|
437
|
-
value: value
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
if (typeof value === 'number') {
|
|
442
|
-
if (isNaN(value)) {
|
|
443
|
-
return {
|
|
444
|
-
error: 'invalid',
|
|
445
|
-
reason: 'invalid_number'
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
if (!isFinite(value)) {
|
|
450
|
-
return {
|
|
451
|
-
error: 'invalid',
|
|
452
|
-
reason: 'out_of_bounds'
|
|
453
|
-
};
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
var date = parseDate(value, options.properties);
|
|
457
|
-
|
|
458
|
-
if (isNaN(date.valueOf())) {
|
|
459
|
-
return {
|
|
460
|
-
error: 'invalid',
|
|
461
|
-
reason: 'out_of_bounds'
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
return {
|
|
466
|
-
value: date
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
return {
|
|
471
|
-
error: 'invalid',
|
|
472
|
-
reason: 'not_a_date'
|
|
473
|
-
};
|
|
287
|
+
return parseCustomValue(value, function (value) {
|
|
288
|
+
return DateType(value, {
|
|
289
|
+
properties: options.properties
|
|
290
|
+
});
|
|
291
|
+
});
|
|
474
292
|
|
|
475
293
|
case Boolean:
|
|
476
|
-
|
|
477
|
-
return {
|
|
478
|
-
value: value
|
|
479
|
-
};
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
return {
|
|
483
|
-
error: 'invalid',
|
|
484
|
-
reason: 'not_a_boolean'
|
|
485
|
-
};
|
|
294
|
+
return parseCustomValue(value, BooleanType);
|
|
486
295
|
|
|
487
296
|
default:
|
|
488
297
|
if (typeof type === 'function') {
|
|
489
298
|
return parseCustomValue(value, type);
|
|
490
299
|
}
|
|
491
300
|
|
|
492
|
-
throw new Error("
|
|
301
|
+
throw new Error("Unsupported schema type: ".concat(type && type.name || type));
|
|
493
302
|
}
|
|
494
303
|
}
|
|
495
304
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertToJson.js","names":["parseDate","Integer","isInteger","URL","isURL","Email","isEmail","DEFAULT_OPTIONS","isColumnOriented","data","schema","options","rowMap","ignoreEmptyRows","validateSchema","transpose","columns","results","errors","i","length","result","read","push","error","row","rows","rowIndex","object","isEmptyObject","key","schemaEntry","isNestedSchema","type","Array","isArray","rawValue","indexOf","undefined","value","reason","notEmpty","array","parseArray","map","_value","parseValue","required","column","includeNullValues","prop","Object","keys","parse","parseCustomValue","parseValueOfType","oneOf","validate","message","String","isNaN","isFinite","Number","stringifiedValue","Date","valueOf","date","properties","Boolean","Error","name","getBlock","string","endCharacter","startIndex","substring","character","block","blocks","index","trim","_","entry"],"sources":["../../../source/read/schema/convertToJson.js"],"sourcesContent":["import parseDate from '../parseDate.js'\r\n\r\nimport Integer, { isInteger } from '../../types/Integer.js'\r\nimport URL, { isURL } from '../../types/URL.js'\r\nimport Email, { isEmail } from '../../types/Email.js'\r\n\r\nconst DEFAULT_OPTIONS = {\r\n isColumnOriented: false\r\n}\r\n\r\n/**\r\n * Convert 2D array to nested objects.\r\n * If row oriented data, row 0 is dotted key names.\r\n * Column oriented data is transposed.\r\n * @param {any[][]} data - An array of rows, each row being an array of cells.\r\n * @param {object} schema\r\n * @return {object[]}\r\n */\r\nexport default function(data, schema, options) {\r\n if (options) {\r\n options = {\r\n ...DEFAULT_OPTIONS,\r\n ...options\r\n }\r\n } else {\r\n options = DEFAULT_OPTIONS\r\n }\r\n\r\n const {\r\n isColumnOriented,\r\n rowMap,\r\n ignoreEmptyRows\r\n } = options\r\n\r\n validateSchema(schema)\r\n\r\n if (isColumnOriented) {\r\n data = transpose(data)\r\n }\r\n\r\n const columns = data[0]\r\n\r\n const results = []\r\n const errors = []\r\n\r\n for (let i = 1; i < data.length; i++) {\r\n const result = read(schema, data[i], i, columns, errors, options)\r\n if (result !== null || ignoreEmptyRows === false) {\r\n results.push(result)\r\n }\r\n }\r\n\r\n // Correct error rows.\r\n if (rowMap) {\r\n for (const error of errors) {\r\n // Convert the `row` index in `data` to the\r\n // actual `row` index in the spreadsheet.\r\n // `- 1` converts row number to row index.\r\n // `+ 1` converts row index to row number.\r\n error.row = rowMap[error.row - 1] + 1\r\n }\r\n }\r\n\r\n return {\r\n rows: results,\r\n errors\r\n }\r\n}\r\n\r\nfunction read(schema, row, rowIndex, columns, errors, options) {\r\n const object = {}\r\n let isEmptyObject = true\r\n for (const key of Object.keys(schema)) {\r\n const schemaEntry = schema[key]\r\n const isNestedSchema = typeof schemaEntry.type === 'object' && !Array.isArray(schemaEntry.type)\r\n let rawValue = row[columns.indexOf(key)]\r\n if (rawValue === undefined) {\r\n rawValue = null\r\n }\r\n let value\r\n let error\r\n let reason\r\n if (isNestedSchema) {\r\n value = read(schemaEntry.type, row, rowIndex, columns, errors, options)\r\n } else {\r\n if (rawValue === null) {\r\n value = null\r\n }\r\n else if (Array.isArray(schemaEntry.type)) {\r\n let notEmpty = false\r\n const array = parseArray(rawValue).map((_value) => {\r\n const result = parseValue(_value, schemaEntry, options)\r\n if (result.error) {\r\n value = _value\r\n error = result.error\r\n reason = result.reason\r\n }\r\n if (result.value !== null) {\r\n notEmpty = true\r\n }\r\n return result.value\r\n })\r\n if (!error) {\r\n value = notEmpty ? array : null\r\n }\r\n } else {\r\n const result = parseValue(rawValue, schemaEntry, options)\r\n error = result.error\r\n reason = result.reason\r\n value = error ? rawValue : result.value\r\n }\r\n }\r\n if (!error && value === null && schemaEntry.required) {\r\n error = 'required'\r\n }\r\n if (error) {\r\n error = {\r\n error,\r\n row: rowIndex + 1,\r\n column: key,\r\n value\r\n }\r\n if (reason) {\r\n error.reason = reason\r\n }\r\n if (schemaEntry.type) {\r\n error.type = schemaEntry.type\r\n }\r\n errors.push(error)\r\n } else {\r\n if (isEmptyObject && value !== null) {\r\n isEmptyObject = false\r\n }\r\n if (value !== null || options.includeNullValues) {\r\n object[schemaEntry.prop] = value\r\n }\r\n }\r\n }\r\n if (isEmptyObject) {\r\n return null\r\n }\r\n return object\r\n}\r\n\r\n/**\r\n * Converts textual value to a javascript typed value.\r\n * @param {any} value\r\n * @param {object} schemaEntry\r\n * @return {{ value: any, error: string }}\r\n */\r\nexport function parseValue(value, schemaEntry, options) {\r\n if (value === null) {\r\n return { value: null }\r\n }\r\n let result\r\n if (schemaEntry.parse) {\r\n result = parseCustomValue(value, schemaEntry.parse)\r\n } else if (schemaEntry.type) {\r\n result = parseValueOfType(\r\n value,\r\n // Supports parsing array types.\r\n // See `parseArray()` function for more details.\r\n // Example `type`: String[]\r\n // Input: 'Barack Obama, \"String, with, colons\", Donald Trump'\r\n // Output: ['Barack Obama', 'String, with, colons', 'Donald Trump']\r\n Array.isArray(schemaEntry.type) ? schemaEntry.type[0] : schemaEntry.type,\r\n options\r\n )\r\n } else {\r\n result = { value: value }\r\n // throw new Error('Invalid schema entry: no .type and no .parse():\\n\\n' + JSON.stringify(schemaEntry, null, 2))\r\n }\r\n // If errored then return the error.\r\n if (result.error) {\r\n return result\r\n }\r\n if (result.value !== null) {\r\n if (schemaEntry.oneOf && schemaEntry.oneOf.indexOf(result.value) < 0) {\r\n return { error: 'invalid', reason: 'unknown' }\r\n }\r\n if (schemaEntry.validate) {\r\n try {\r\n schemaEntry.validate(result.value)\r\n } catch (error) {\r\n return { error: error.message }\r\n }\r\n }\r\n }\r\n return result\r\n}\r\n\r\n/**\r\n * Converts textual value to a custom value using supplied `.parse()`.\r\n * @param {any} value\r\n * @param {function} parse\r\n * @return {{ value: any, error: string }}\r\n */\r\nfunction parseCustomValue(value, parse) {\r\n try {\r\n value = parse(value)\r\n if (value === undefined) {\r\n return { value: null }\r\n }\r\n return { value }\r\n } catch (error) {\r\n return { error: error.message }\r\n }\r\n}\r\n\r\n/**\r\n * Converts textual value to a javascript typed value.\r\n * @param {any} value\r\n * @param {} type\r\n * @return {{ value: (string|number|Date|boolean), error: string, reason?: string }}\r\n */\r\nfunction parseValueOfType(value, type, options) {\r\n switch (type) {\r\n case String:\r\n if (typeof value === 'string') {\r\n return { value }\r\n }\r\n // Excel tends to perform a forced automatic convertion of string-type values\r\n // to number-type ones when the user has input them. Otherwise, users wouldn't\r\n // be able to perform formula calculations on those cell values because users\r\n // won't bother manually choosing a \"numeric\" cell type for each cell, and\r\n // even if they did, choosing a \"numeric\" cell type every time wouldn't be an\r\n // acceptable \"user experience\".\r\n //\r\n // So, if a cell value is supposed to be a string and Excel has automatically\r\n // converted it to a number, perform a backwards conversion.\r\n //\r\n if (typeof value === 'number') {\r\n if (isNaN(value)) {\r\n return { error: 'invalid', reason: 'invalid_number' }\r\n }\r\n // The global `isFinite()` function filters out:\r\n // * NaN\r\n // * -Infinity\r\n // * Infinity\r\n //\r\n // All other values pass (including non-numbers).\r\n //\r\n if (!isFinite(value)) {\r\n return { error: 'invalid', reason: 'out_of_bounds' }\r\n }\r\n return { value: String(value) }\r\n }\r\n return { error: 'invalid', reason: 'not_a_string' }\r\n\r\n case Number:\r\n case Integer:\r\n // An XLSX file editing software might not always correctly\r\n // detect numeric values in string-type cells. Users won't bother\r\n // manually selecting a cell type, so the editing software has to guess\r\n // based on the user's input. One can assume that such auto-detection\r\n // might not always work.\r\n //\r\n // So, if a cell is supposed to be a numeric one, convert a string value to a number.\r\n //\r\n if (typeof value === 'string') {\r\n const stringifiedValue = value\r\n value = Number(value)\r\n if (String(value) !== stringifiedValue) {\r\n return { error: 'invalid', reason: 'not_a_number' }\r\n }\r\n }\r\n if (typeof value !== 'number') {\r\n return { error: 'invalid', reason: 'not_a_number' }\r\n }\r\n if (isNaN(value)) {\r\n return { error: 'invalid', reason: 'invalid_number' }\r\n }\r\n // At this point, `value` can only be a number.\r\n //\r\n // The global `isFinite()` function filters out:\r\n // * NaN\r\n // * -Infinity\r\n // * Infinity\r\n //\r\n // All other values pass (including non-numbers).\r\n //\r\n if (!isFinite(value)) {\r\n return { error: 'invalid', reason: 'out_of_bounds' }\r\n }\r\n if (type === Integer && !isInteger(value)) {\r\n return { error: 'invalid', reason: 'not_an_integer' }\r\n }\r\n return { value }\r\n\r\n case URL:\r\n if (typeof value === 'string') {\r\n if (isURL(value)) {\r\n return { value }\r\n }\r\n return { error: 'invalid', reason: 'not_a_url' }\r\n }\r\n return { error: 'invalid', reason: 'not_a_string' }\r\n\r\n case Email:\r\n if (typeof value === 'string') {\r\n if (isEmail(value)) {\r\n return { value }\r\n }\r\n return { error: 'invalid', reason: 'not_an_email' }\r\n }\r\n return { error: 'invalid', reason: 'not_a_string' }\r\n\r\n case Date:\r\n // XLSX has no specific format for dates.\r\n // Sometimes a date can be heuristically detected.\r\n // https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777\r\n if (value instanceof Date) {\r\n if (isNaN(value.valueOf())) {\r\n return { error: 'invalid', reason: 'out_of_bounds' }\r\n }\r\n return { value }\r\n }\r\n if (typeof value === 'number') {\r\n if (isNaN(value)) {\r\n return { error: 'invalid', reason: 'invalid_number' }\r\n }\r\n if (!isFinite(value)) {\r\n return { error: 'invalid', reason: 'out_of_bounds' }\r\n }\r\n const date = parseDate(value, options.properties)\r\n if (isNaN(date.valueOf())) {\r\n return { error: 'invalid', reason: 'out_of_bounds' }\r\n }\r\n return { value: date }\r\n }\r\n return { error: 'invalid', reason: 'not_a_date' }\r\n\r\n case Boolean:\r\n if (typeof value === 'boolean') {\r\n return { value }\r\n }\r\n return { error: 'invalid', reason: 'not_a_boolean' }\r\n\r\n default:\r\n if (typeof type === 'function') {\r\n return parseCustomValue(value, type)\r\n }\r\n throw new Error(`Unknown schema type: ${type && type.name || type}`)\r\n }\r\n}\r\n\r\nexport function getBlock(string, endCharacter, startIndex) {\r\n let i = 0\r\n let substring = ''\r\n let character\r\n while (startIndex + i < string.length) {\r\n const character = string[startIndex + i]\r\n if (character === endCharacter) {\r\n return [substring, i]\r\n }\r\n else if (character === '\"') {\r\n const block = getBlock(string, '\"', startIndex + i + 1)\r\n substring += block[0]\r\n i += '\"'.length + block[1] + '\"'.length\r\n }\r\n else {\r\n substring += character\r\n i++\r\n }\r\n }\r\n return [substring, i]\r\n}\r\n\r\n/**\r\n * Parses a string of comma-separated substrings into an array of substrings.\r\n * (the `export` is just for tests)\r\n * @param {string} string — A string of comma-separated substrings.\r\n * @return {string[]} An array of substrings.\r\n */\r\nexport function parseArray(string) {\r\n const blocks = []\r\n let index = 0\r\n while (index < string.length) {\r\n const [substring, length] = getBlock(string, ',', index)\r\n index += length + ','.length\r\n blocks.push(substring.trim())\r\n }\r\n return blocks\r\n}\r\n\r\n// Transpose a 2D array.\r\n// https://stackoverflow.com/questions/17428587/transposing-a-2d-array-in-javascript\r\nconst transpose = array => array[0].map((_, i) => array.map(row => row[i]))\r\n\r\nfunction validateSchema(schema) {\r\n for (const key of Object.keys(schema)) {\r\n const entry = schema[key]\r\n if (!entry.prop) {\r\n throw new Error(`\"prop\" not defined for schema entry \"${key}\".`)\r\n }\r\n }\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,SAAP,MAAsB,iBAAtB;AAEA,OAAOC,OAAP,IAAkBC,SAAlB,QAAmC,wBAAnC;AACA,OAAOC,GAAP,IAAcC,KAAd,QAA2B,oBAA3B;AACA,OAAOC,KAAP,IAAgBC,OAAhB,QAA+B,sBAA/B;AAEA,IAAMC,eAAe,GAAG;EACtBC,gBAAgB,EAAE;AADI,CAAxB;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,UAASC,IAAT,EAAeC,MAAf,EAAuBC,OAAvB,EAAgC;EAC7C,IAAIA,OAAJ,EAAa;IACXA,OAAO,mCACFJ,eADE,GAEFI,OAFE,CAAP;EAID,CALD,MAKO;IACLA,OAAO,GAAGJ,eAAV;EACD;;EAED,eAIII,OAJJ;EAAA,IACEH,gBADF,YACEA,gBADF;EAAA,IAEEI,MAFF,YAEEA,MAFF;EAAA,IAGEC,eAHF,YAGEA,eAHF;EAMAC,cAAc,CAACJ,MAAD,CAAd;;EAEA,IAAIF,gBAAJ,EAAsB;IACpBC,IAAI,GAAGM,SAAS,CAACN,IAAD,CAAhB;EACD;;EAED,IAAMO,OAAO,GAAGP,IAAI,CAAC,CAAD,CAApB;EAEA,IAAMQ,OAAO,GAAG,EAAhB;EACA,IAAMC,MAAM,GAAG,EAAf;;EAEA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGV,IAAI,CAACW,MAAzB,EAAiCD,CAAC,EAAlC,EAAsC;IACpC,IAAME,MAAM,GAAGC,IAAI,CAACZ,MAAD,EAASD,IAAI,CAACU,CAAD,CAAb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G,SAAZA,SAAY,CAAA2B,KAAK;EAAA,OAAIA,KAAK,CAAC,CAAD,CAAL,CAASE,GAAT,CAAa,UAACqC,CAAD,EAAI9D,CAAJ;IAAA,OAAUuB,KAAK,CAACE,GAAN,CAAU,UAAAnB,GAAG;MAAA,OAAIA,GAAG,CAACN,CAAD,CAAP;IAAA,CAAb,CAAV;EAAA,CAAb,CAAJ;AAAA,CAAvB;;AAEA,SAASL,cAAT,CAAwBJ,MAAxB,EAAgC;EAC9B,kCAAkByC,MAAM,CAACC,IAAP,CAAY1C,MAAZ,CAAlB,qCAAuC;IAAlC,IAAMoB,GAAG,qBAAT;IACH,IAAMoD,KAAK,GAAGxE,MAAM,CAACoB,GAAD,CAApB;;IACA,IAAI,CAACoD,KAAK,CAAChC,IAAX,EAAiB;MACf,MAAM,IAAImB,KAAJ,mDAAkDvC,GAAlD,SAAN;IACD;EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"convertToJson.js","names":["NumberType","StringType","BooleanType","DateType","DEFAULT_OPTIONS","isColumnOriented","data","schema","options","rowMap","ignoreEmptyRows","validateSchema","transpose","columns","results","errors","i","length","result","read","push","error","row","rows","rowIndex","object","isEmptyObject","key","schemaEntry","isNestedSchema","type","Array","isArray","rawValue","indexOf","undefined","value","reason","notEmpty","array","parseArray","map","_value","parseValue","required","column","includeNullValues","prop","Object","keys","parse","parseCustomValue","parseValueOfType","oneOf","validate","message","String","Number","Date","properties","Boolean","Error","name","getBlock","string","endCharacter","startIndex","substring","character","block","blocks","index","trim","_","entry"],"sources":["../../../source/read/schema/convertToJson.js"],"sourcesContent":["import NumberType from '../../types/Number.js'\r\nimport StringType from '../../types/String.js'\r\nimport BooleanType from '../../types/Boolean.js'\r\nimport DateType from '../../types/Date.js'\r\n\r\nconst DEFAULT_OPTIONS = {\r\n isColumnOriented: false\r\n}\r\n\r\n/**\r\n * Convert 2D array to nested objects.\r\n * If row oriented data, row 0 is dotted key names.\r\n * Column oriented data is transposed.\r\n * @param {any[][]} data - An array of rows, each row being an array of cells.\r\n * @param {object} schema\r\n * @return {object[]}\r\n */\r\nexport default function(data, schema, options) {\r\n if (options) {\r\n options = {\r\n ...DEFAULT_OPTIONS,\r\n ...options\r\n }\r\n } else {\r\n options = DEFAULT_OPTIONS\r\n }\r\n\r\n const {\r\n isColumnOriented,\r\n rowMap,\r\n ignoreEmptyRows\r\n } = options\r\n\r\n validateSchema(schema)\r\n\r\n if (isColumnOriented) {\r\n data = transpose(data)\r\n }\r\n\r\n const columns = data[0]\r\n\r\n const results = []\r\n const errors = []\r\n\r\n for (let i = 1; i < data.length; i++) {\r\n const result = read(schema, data[i], i, columns, errors, options)\r\n if (result !== null || ignoreEmptyRows === false) {\r\n results.push(result)\r\n }\r\n }\r\n\r\n // Correct error rows.\r\n if (rowMap) {\r\n for (const error of errors) {\r\n // Convert the `row` index in `data` to the\r\n // actual `row` index in the spreadsheet.\r\n // `- 1` converts row number to row index.\r\n // `+ 1` converts row index to row number.\r\n error.row = rowMap[error.row - 1] + 1\r\n }\r\n }\r\n\r\n return {\r\n rows: results,\r\n errors\r\n }\r\n}\r\n\r\nfunction read(schema, row, rowIndex, columns, errors, options) {\r\n const object = {}\r\n let isEmptyObject = true\r\n for (const key of Object.keys(schema)) {\r\n const schemaEntry = schema[key]\r\n const isNestedSchema = typeof schemaEntry.type === 'object' && !Array.isArray(schemaEntry.type)\r\n let rawValue = row[columns.indexOf(key)]\r\n if (rawValue === undefined) {\r\n rawValue = null\r\n }\r\n let value\r\n let error\r\n let reason\r\n if (isNestedSchema) {\r\n value = read(schemaEntry.type, row, rowIndex, columns, errors, options)\r\n } else {\r\n if (rawValue === null) {\r\n value = null\r\n }\r\n else if (Array.isArray(schemaEntry.type)) {\r\n let notEmpty = false\r\n const array = parseArray(rawValue).map((_value) => {\r\n const result = parseValue(_value, schemaEntry, options)\r\n if (result.error) {\r\n value = _value\r\n error = result.error\r\n reason = result.reason\r\n }\r\n if (result.value !== null) {\r\n notEmpty = true\r\n }\r\n return result.value\r\n })\r\n if (!error) {\r\n value = notEmpty ? array : null\r\n }\r\n } else {\r\n const result = parseValue(rawValue, schemaEntry, options)\r\n error = result.error\r\n reason = result.reason\r\n value = error ? rawValue : result.value\r\n }\r\n }\r\n if (!error && value === null && schemaEntry.required) {\r\n error = 'required'\r\n }\r\n if (error) {\r\n error = {\r\n error,\r\n row: rowIndex + 1,\r\n column: key,\r\n value\r\n }\r\n if (reason) {\r\n error.reason = reason\r\n }\r\n if (schemaEntry.type) {\r\n error.type = schemaEntry.type\r\n }\r\n errors.push(error)\r\n } else {\r\n if (isEmptyObject && value !== null) {\r\n isEmptyObject = false\r\n }\r\n if (value !== null || options.includeNullValues) {\r\n object[schemaEntry.prop] = value\r\n }\r\n }\r\n }\r\n if (isEmptyObject) {\r\n return null\r\n }\r\n return object\r\n}\r\n\r\n/**\r\n * Converts textual value to a javascript typed value.\r\n * @param {any} value\r\n * @param {object} schemaEntry\r\n * @return {{ value: any, error: string }}\r\n */\r\nexport function parseValue(value, schemaEntry, options) {\r\n if (value === null) {\r\n return { value: null }\r\n }\r\n let result\r\n if (schemaEntry.parse) {\r\n result = parseCustomValue(value, schemaEntry.parse)\r\n } else if (schemaEntry.type) {\r\n result = parseValueOfType(\r\n value,\r\n // Supports parsing array types.\r\n // See `parseArray()` function for more details.\r\n // Example `type`: String[]\r\n // Input: 'Barack Obama, \"String, with, colons\", Donald Trump'\r\n // Output: ['Barack Obama', 'String, with, colons', 'Donald Trump']\r\n Array.isArray(schemaEntry.type) ? schemaEntry.type[0] : schemaEntry.type,\r\n options\r\n )\r\n } else {\r\n result = { value: value }\r\n // throw new Error('Invalid schema entry: no .type and no .parse():\\n\\n' + JSON.stringify(schemaEntry, null, 2))\r\n }\r\n // If errored then return the error.\r\n if (result.error) {\r\n return result\r\n }\r\n if (result.value !== null) {\r\n if (schemaEntry.oneOf && schemaEntry.oneOf.indexOf(result.value) < 0) {\r\n return { error: 'invalid', reason: 'unknown' }\r\n }\r\n if (schemaEntry.validate) {\r\n try {\r\n schemaEntry.validate(result.value)\r\n } catch (error) {\r\n return { error: error.message }\r\n }\r\n }\r\n }\r\n return result\r\n}\r\n\r\n/**\r\n * Converts textual value to a custom value using supplied `.parse()`.\r\n * @param {any} value\r\n * @param {function} parse\r\n * @return {{ value: any, error: string }}\r\n */\r\nfunction parseCustomValue(value, parse) {\r\n try {\r\n value = parse(value)\r\n if (value === undefined) {\r\n return { value: null }\r\n }\r\n return { value }\r\n } catch (error) {\r\n const result = { error: error.message }\r\n if (error.reason) {\r\n result.reason = error.reason;\r\n }\r\n return result\r\n }\r\n}\r\n\r\n/**\r\n * Converts textual value to a javascript typed value.\r\n * @param {any} value\r\n * @param {} type\r\n * @return {{ value: (string|number|Date|boolean), error: string, reason?: string }}\r\n */\r\nfunction parseValueOfType(value, type, options) {\r\n switch (type) {\r\n case String:\r\n return parseCustomValue(value, StringType)\r\n\r\n case Number:\r\n return parseCustomValue(value, NumberType)\r\n\r\n case Date:\r\n return parseCustomValue(value, (value) => DateType(value, { properties: options.properties }))\r\n\r\n case Boolean:\r\n return parseCustomValue(value, BooleanType)\r\n\r\n default:\r\n if (typeof type === 'function') {\r\n return parseCustomValue(value, type)\r\n }\r\n throw new Error(`Unsupported schema type: ${type && type.name || type}`)\r\n }\r\n}\r\n\r\nexport function getBlock(string, endCharacter, startIndex) {\r\n let i = 0\r\n let substring = ''\r\n let character\r\n while (startIndex + i < string.length) {\r\n const character = string[startIndex + i]\r\n if (character === endCharacter) {\r\n return [substring, i]\r\n }\r\n else if (character === '\"') {\r\n const block = getBlock(string, '\"', startIndex + i + 1)\r\n substring += block[0]\r\n i += '\"'.length + block[1] + '\"'.length\r\n }\r\n else {\r\n substring += character\r\n i++\r\n }\r\n }\r\n return [substring, i]\r\n}\r\n\r\n/**\r\n * Parses a string of comma-separated substrings into an array of substrings.\r\n * (the `export` is just for tests)\r\n * @param {string} string — A string of comma-separated substrings.\r\n * @return {string[]} An array of substrings.\r\n */\r\nexport function parseArray(string) {\r\n const blocks = []\r\n let index = 0\r\n while (index < string.length) {\r\n const [substring, length] = getBlock(string, ',', index)\r\n index += length + ','.length\r\n blocks.push(substring.trim())\r\n }\r\n return blocks\r\n}\r\n\r\n// Transpose a 2D array.\r\n// https://stackoverflow.com/questions/17428587/transposing-a-2d-array-in-javascript\r\nconst transpose = array => array[0].map((_, i) => array.map(row => row[i]))\r\n\r\nfunction validateSchema(schema) {\r\n for (const key of Object.keys(schema)) {\r\n const entry = schema[key]\r\n if (!entry.prop) {\r\n throw new Error(`\"prop\" not defined for schema entry \"${key}\".`)\r\n }\r\n }\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,UAAP,MAAuB,uBAAvB;AACA,OAAOC,UAAP,MAAuB,uBAAvB;AACA,OAAOC,WAAP,MAAwB,wBAAxB;AACA,OAAOC,QAAP,MAAqB,qBAArB;AAEA,IAAMC,eAAe,GAAG;EACtBC,gBAAgB,EAAE;AADI,CAAxB;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,UAASC,IAAT,EAAeC,MAAf,EAAuBC,OAAvB,EAAgC;EAC7C,IAAIA,OAAJ,EAAa;IACXA,OAAO,mCACFJ,eADE,GAEFI,OAFE,CAAP;EAID,CALD,MAKO;IACLA,OAAO,GAAGJ,eAAV;EACD;;EAED,eAIII,OAJJ;EAAA,IACEH,gBADF,YACEA,gBADF;EAAA,IAEEI,MAFF,YAEEA,MAFF;EAAA,IAGEC,eAHF,YAGEA,eAHF;EAMAC,cAAc,CAACJ,MAAD,CAAd;;EAEA,IAAIF,gBAAJ,EAAsB;IACpBC,IAAI,GAAGM,SAAS,CAACN,IAAD,CAAhB;EACD;;EAED,IAAMO,OAAO,GAAGP,IAAI,CAAC,CAAD,CAApB;EAEA,IAAMQ,OAAO,GAAG,EAAhB;EACA,IAAMC,MAAM,GAAG,EAAf;;EAEA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGV,IAAI,CAACW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