read-excel-file 5.5.3 → 5.6.1
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 +5 -3
- package/bundle/read-excel-file.min.js +1 -1
- package/bundle/read-excel-file.min.js.map +1 -1
- package/commonjs/read/isDateTimestamp.js +5 -1
- package/commonjs/read/isDateTimestamp.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/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/modules/read/isDateTimestamp.js +5 -1
- package/modules/read/isDateTimestamp.js.map +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/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
|
@@ -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"}
|
|
@@ -22,8 +22,12 @@ export default function isDateTimestamp(value, styleId, styles, options) {
|
|
|
22
22
|
throw new Error("Cell style not found: ".concat(styleId));
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
if (!style.numberFormat) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
25
29
|
if ( // Whether it's a "number format" that's conventionally used for storing date timestamps.
|
|
26
|
-
BUILT_IN_DATE_NUMBER_FORMAT_IDS.indexOf(
|
|
30
|
+
BUILT_IN_DATE_NUMBER_FORMAT_IDS.indexOf(Number(style.numberFormat.id)) >= 0 || // Whether it's a "number format" that uses a "formatting template"
|
|
27
31
|
// that the developer is certain is a date formatting template.
|
|
28
32
|
options.dateFormat && style.numberFormat.template === options.dateFormat || // Whether the "smart formatting template" feature is not disabled
|
|
29
33
|
// and it has detected that it's a date formatting template by looking at it.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isDateTimestamp.js","names":["isDateTimestamp","value","styleId","styles","options","style","Error","
|
|
1
|
+
{"version":3,"file":"isDateTimestamp.js","names":["isDateTimestamp","value","styleId","styles","options","style","Error","numberFormat","BUILT_IN_DATE_NUMBER_FORMAT_IDS","indexOf","Number","id","dateFormat","template","smartDateParser","isDateTemplate","DATE_FORMAT_WEIRD_PREFIX","DATE_FORMAT_WEIRD_POSTFIX","toLowerCase","replace","tokens","split","token","DATE_TEMPLATE_TOKENS"],"sources":["../../source/read/isDateTimestamp.js"],"sourcesContent":["// XLSX does have \"d\" type for dates, but it's not commonly used.\r\n// Instead, it prefers using \"n\" type for storing dates as timestamps.\r\n//\r\n// Whether a numeric value is a number or a date timestamp, it sometimes could be\r\n// detected by looking at the value \"format\" and seeing if it's a date-specific one.\r\n// https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777\r\n//\r\n// The list of generic numeric value \"formats\":\r\n// https://xlsxwriter.readthedocs.io/format.html#format-set-num-format\r\n//\r\nexport default function isDateTimestamp(value, styleId, styles, options) {\r\n if (styleId) {\r\n const style = styles[styleId]\r\n if (!style) {\r\n throw new Error(`Cell style not found: ${styleId}`)\r\n }\r\n if (!style.numberFormat) {\r\n return false\r\n }\r\n if (\r\n // Whether it's a \"number format\" that's conventionally used for storing date timestamps.\r\n BUILT_IN_DATE_NUMBER_FORMAT_IDS.indexOf(Number(style.numberFormat.id)) >= 0 ||\r\n // Whether it's a \"number format\" that uses a \"formatting template\"\r\n // that the developer is certain is a date formatting template.\r\n (options.dateFormat && style.numberFormat.template === options.dateFormat) ||\r\n // Whether the \"smart formatting template\" feature is not disabled\r\n // and it has detected that it's a date formatting template by looking at it.\r\n (options.smartDateParser !== false && style.numberFormat.template && isDateTemplate(style.numberFormat.template))\r\n ) {\r\n return true\r\n }\r\n }\r\n}\r\n\r\n// https://hexdocs.pm/xlsxir/number_styles.html\r\nconst BUILT_IN_DATE_NUMBER_FORMAT_IDS = [14,15,16,17,18,19,20,21,22,27,30,36,45,46,47,50,57]\r\n\r\n// On some date formats, there's an \"[$-414]\" prefix.\r\n// I don't have any idea what that is.\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// Examples:\r\n//\r\n// * 27 (built-in format) \"[$-404]e/m/d\"\r\n// * 164 (custom format) \"[$-414]mmmm\\ yyyy;@\"\r\n//\r\nconst DATE_FORMAT_WEIRD_PREFIX = /^\\[\\$-414\\]/\r\n\r\n// On some date formats, there's an \";@\" postfix.\r\n// I don't have any idea what that is.\r\n// Examples:\r\n//\r\n// * 164 (custom format) \"m/d/yyyy;@\"\r\n// * 164 (custom format) \"[$-414]mmmm\\ yyyy;@\"\r\n//\r\nconst DATE_FORMAT_WEIRD_POSTFIX = /;@$/\r\n\r\nfunction isDateTemplate(template) {\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 lowercase the template first.\r\n template = template.toLowerCase()\r\n\r\n // On some date formats, there's an \"[$-414]\" prefix.\r\n // I don't have any idea what that is. Trim it.\r\n template = template.replace(DATE_FORMAT_WEIRD_PREFIX, '')\r\n\r\n // On some date formats, there's an \";@\" postfix.\r\n // I don't have any idea what that is. Trim it.\r\n template = template.replace(DATE_FORMAT_WEIRD_POSTFIX, '')\r\n\r\n const tokens = template.split(/\\W+/)\r\n for (const token of tokens) {\r\n if (DATE_TEMPLATE_TOKENS.indexOf(token) < 0) {\r\n return false\r\n }\r\n }\r\n return true\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\nconst 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,eAAe,SAASA,eAAT,CAAyBC,KAAzB,EAAgCC,OAAhC,EAAyCC,MAAzC,EAAiDC,OAAjD,EAA0D;EACvE,IAAIF,OAAJ,EAAa;IACX,IAAMG,KAAK,GAAGF,MAAM,CAACD,OAAD,CAApB;;IACA,IAAI,CAACG,KAAL,EAAY;MACV,MAAM,IAAIC,KAAJ,iCAAmCJ,OAAnC,EAAN;IACD;;IACD,IAAI,CAACG,KAAK,CAACE,YAAX,EAAyB;MACvB,OAAO,KAAP;IACD;;IACD,KACE;IACAC,+BAA+B,CAACC,OAAhC,CAAwCC,MAAM,CAACL,KAAK,CAACE,YAAN,CAAmBI,EAApB,CAA9C,KAA0E,CAA1E,IACA;IACA;IACCP,OAAO,CAACQ,UAAR,IAAsBP,KAAK,CAACE,YAAN,CAAmBM,QAAnB,KAAgCT,OAAO,CAACQ,UAH/D,IAIA;IACA;IACCR,OAAO,CAACU,eAAR,KAA4B,KAA5B,IAAqCT,KAAK,CAACE,YAAN,CAAmBM,QAAxD,IAAoEE,cAAc,CAACV,KAAK,CAACE,YAAN,CAAmBM,QAApB,CARrF,EASG;MACD,OAAO,IAAP;IACD;EACF;AACF,C,CAED;;AACA,IAAML,+BAA+B,GAAG,CAAC,EAAD,EAAI,EAAJ,EAAO,EAAP,EAAU,EAAV,EAAa,EAAb,EAAgB,EAAhB,EAAmB,EAAnB,EAAsB,EAAtB,EAAyB,EAAzB,EAA4B,EAA5B,EAA+B,EAA/B,EAAkC,EAAlC,EAAqC,EAArC,EAAwC,EAAxC,EAA2C,EAA3C,EAA8C,EAA9C,EAAiD,EAAjD,CAAxC,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMQ,wBAAwB,GAAG,aAAjC,C,CAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,IAAMC,yBAAyB,GAAG,KAAlC;;AAEA,SAASF,cAAT,CAAwBF,QAAxB,EAAkC;EAChC;EACA;EACA;EACAA,QAAQ,GAAGA,QAAQ,CAACK,WAAT,EAAX,CAJgC,CAMhC;EACA;;EACAL,QAAQ,GAAGA,QAAQ,CAACM,OAAT,CAAiBH,wBAAjB,EAA2C,EAA3C,CAAX,CARgC,CAUhC;EACA;;EACAH,QAAQ,GAAGA,QAAQ,CAACM,OAAT,CAAiBF,yBAAjB,EAA4C,EAA5C,CAAX;EAEA,IAAMG,MAAM,GAAGP,QAAQ,CAACQ,KAAT,CAAe,KAAf,CAAf;;EACA,qDAAoBD,MAApB,wCAA4B;IAAA,IAAjBE,KAAiB;;IAC1B,IAAIC,oBAAoB,CAACd,OAArB,CAA6Ba,KAA7B,IAAsC,CAA1C,EAA6C;MAC3C,OAAO,KAAP;IACD;EACF;;EACD,OAAO,IAAP;AACD,C,CAED;AACA;;;AACA,IAAMC,oBAAoB,GAAG,CAC3B;AACA,IAF2B,EAG3B;AACA,IAJ2B,EAK3B;AACA,GAN2B,EAO3B;AACA,IAR2B,EAS3B;AACA,IAV2B,EAW3B;AACA,IAZ2B,EAa3B;AACA,GAd2B,EAe3B;AACA,IAhB2B,EAiB3B;AACA,GAlB2B,EAmB3B;AACA,IApB2B,EAqB3B;AACA,KAtB2B,EAuB3B;AACA,MAxB2B,EAyB3B;AACA,IA1B2B,EA2B3B;AACA,MA5B2B,EA8B3B;AACA;AACA;AACA;AACA;AACA;AACA,GApC2B,CAA7B"}
|
|
@@ -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":"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"}
|
|
@@ -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
|
|