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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { unzipSync, strFromU8 } from 'fflate';
|
|
2
2
|
/**
|
|
3
3
|
* Reads XLSX file in a browser.
|
|
4
|
-
* @param {(File|ArrayBuffer)} input - A `File` or an `ArrayBuffer`.
|
|
4
|
+
* @param {(File|Blob|ArrayBuffer)} input - A `File` or an `ArrayBuffer`.
|
|
5
5
|
* @return {Promise} Resolves to an object holding XLSX file entries.
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -10,13 +10,22 @@ export default function unpackXlsxFile(input) {
|
|
|
10
10
|
return input.arrayBuffer().then(unpackXlsxArrayBuffer);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
if (input instanceof Blob) {
|
|
14
|
+
return input.arrayBuffer().then(unpackXlsxArrayBuffer);
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
return unpackXlsxArrayBuffer(input);
|
|
14
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Reads XLSX file in a browser from an `ArrayBuffer`.
|
|
21
|
+
* @param {ArrayBuffer} input
|
|
22
|
+
* @return {Promise} Resolves to an object holding XLSX file entries.
|
|
23
|
+
*/
|
|
15
24
|
|
|
16
25
|
function unpackXlsxArrayBuffer(arrayBuffer) {
|
|
17
26
|
var archive = new Uint8Array(arrayBuffer);
|
|
18
27
|
var contents = unzipSync(archive);
|
|
19
|
-
return getContents(contents); // return new Promise((resolve, reject) => {
|
|
28
|
+
return Promise.resolve(getContents(contents)); // return new Promise((resolve, reject) => {
|
|
20
29
|
// unzip(archive, (error, contents) => {
|
|
21
30
|
// if (error) {
|
|
22
31
|
// return reject(error)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unpackXlsxFileBrowser.js","names":["unzipSync","strFromU8","unpackXlsxFile","input","File","arrayBuffer","then","unpackXlsxArrayBuffer","archive","Uint8Array","contents","getContents","unzippedFiles","Object","keys","key"],"sources":["../../source/read/unpackXlsxFileBrowser.js"],"sourcesContent":["import { unzipSync, strFromU8 } from 'fflate'\r\n\r\n/**\r\n * Reads XLSX file in a browser.\r\n * @param {(File|ArrayBuffer)} input - A `File` or an `ArrayBuffer`.\r\n * @return {Promise} Resolves to an object holding XLSX file entries.\r\n */\r\nexport default function unpackXlsxFile(input) {\r\n\tif (input instanceof File) {\r\n\t\treturn input.arrayBuffer().then(unpackXlsxArrayBuffer)\r\n\t}\r\n\treturn unpackXlsxArrayBuffer(input)\r\n}\r\n\r\nfunction unpackXlsxArrayBuffer(arrayBuffer) {\r\n\tconst archive = new Uint8Array(arrayBuffer)\r\n\tconst contents = unzipSync(archive)\r\n\treturn getContents(contents)\r\n\t// return new Promise((resolve, reject) => {\r\n\t// \tunzip(archive, (error, contents) => {\r\n\t// \t\tif (error) {\r\n\t// \t\t\treturn reject(error)\r\n\t// \t\t}\r\n\t// \t\treturn resolve(getContents(contents))\r\n\t// \t})\r\n\t// })\r\n}\r\n\r\nfunction getContents(contents) {\r\n\tconst unzippedFiles = []\r\n\tfor (const key of Object.keys(contents)) {\r\n\t\tunzippedFiles[key] = strFromU8(contents[key])\r\n\t}\r\n\treturn unzippedFiles\r\n}"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,SAApB,QAAqC,QAArC;AAEA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,cAAT,CAAwBC,KAAxB,EAA+B;EAC7C,IAAIA,KAAK,YAAYC,IAArB,EAA2B;IAC1B,OAAOD,KAAK,CAACE,WAAN,GAAoBC,IAApB,CAAyBC,qBAAzB,CAAP;EACA;;EACD,OAAOA,qBAAqB,CAACJ,KAAD,CAA5B;AACA;;
|
|
1
|
+
{"version":3,"file":"unpackXlsxFileBrowser.js","names":["unzipSync","strFromU8","unpackXlsxFile","input","File","arrayBuffer","then","unpackXlsxArrayBuffer","Blob","archive","Uint8Array","contents","Promise","resolve","getContents","unzippedFiles","Object","keys","key"],"sources":["../../source/read/unpackXlsxFileBrowser.js"],"sourcesContent":["import { unzipSync, strFromU8 } from 'fflate'\r\n\r\n/**\r\n * Reads XLSX file in a browser.\r\n * @param {(File|Blob|ArrayBuffer)} input - A `File` or an `ArrayBuffer`.\r\n * @return {Promise} Resolves to an object holding XLSX file entries.\r\n */\r\nexport default function unpackXlsxFile(input) {\r\n\tif (input instanceof File) {\r\n\t\treturn input.arrayBuffer().then(unpackXlsxArrayBuffer)\r\n\t}\r\n\tif (input instanceof Blob) {\r\n\t\treturn input.arrayBuffer().then(unpackXlsxArrayBuffer)\r\n\t}\r\n\treturn unpackXlsxArrayBuffer(input)\r\n}\r\n\r\n/**\r\n * Reads XLSX file in a browser from an `ArrayBuffer`.\r\n * @param {ArrayBuffer} input\r\n * @return {Promise} Resolves to an object holding XLSX file entries.\r\n */\r\nfunction unpackXlsxArrayBuffer(arrayBuffer) {\r\n\tconst archive = new Uint8Array(arrayBuffer)\r\n\tconst contents = unzipSync(archive)\r\n\treturn Promise.resolve(getContents(contents))\r\n\t// return new Promise((resolve, reject) => {\r\n\t// \tunzip(archive, (error, contents) => {\r\n\t// \t\tif (error) {\r\n\t// \t\t\treturn reject(error)\r\n\t// \t\t}\r\n\t// \t\treturn resolve(getContents(contents))\r\n\t// \t})\r\n\t// })\r\n}\r\n\r\nfunction getContents(contents) {\r\n\tconst unzippedFiles = []\r\n\tfor (const key of Object.keys(contents)) {\r\n\t\tunzippedFiles[key] = strFromU8(contents[key])\r\n\t}\r\n\treturn unzippedFiles\r\n}"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,SAApB,QAAqC,QAArC;AAEA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,cAAT,CAAwBC,KAAxB,EAA+B;EAC7C,IAAIA,KAAK,YAAYC,IAArB,EAA2B;IAC1B,OAAOD,KAAK,CAACE,WAAN,GAAoBC,IAApB,CAAyBC,qBAAzB,CAAP;EACA;;EACD,IAAIJ,KAAK,YAAYK,IAArB,EAA2B;IAC1B,OAAOL,KAAK,CAACE,WAAN,GAAoBC,IAApB,CAAyBC,qBAAzB,CAAP;EACA;;EACD,OAAOA,qBAAqB,CAACJ,KAAD,CAA5B;AACA;AAED;AACA;AACA;AACA;AACA;;AACA,SAASI,qBAAT,CAA+BF,WAA/B,EAA4C;EAC3C,IAAMI,OAAO,GAAG,IAAIC,UAAJ,CAAeL,WAAf,CAAhB;EACA,IAAMM,QAAQ,GAAGX,SAAS,CAACS,OAAD,CAA1B;EACA,OAAOG,OAAO,CAACC,OAAR,CAAgBC,WAAW,CAACH,QAAD,CAA3B,CAAP,CAH2C,CAI3C;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AACA;;AAED,SAASG,WAAT,CAAqBH,QAArB,EAA+B;EAC9B,IAAMI,aAAa,GAAG,EAAtB;;EACA,gCAAkBC,MAAM,CAACC,IAAP,CAAYN,QAAZ,CAAlB,kCAAyC;IAApC,IAAMO,GAAG,mBAAT;IACJH,aAAa,CAACG,GAAD,CAAb,GAAqBjB,SAAS,CAACU,QAAQ,CAACO,GAAD,CAAT,CAA9B;EACA;;EACD,OAAOH,aAAP;AACA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Boolean.js","names":["InvalidError","BooleanType","value"],"sources":["../../source/types/Boolean.js"],"sourcesContent":["import InvalidError from './InvalidError.js'\r\n\r\nexport default function BooleanType(value) {\r\n\tif (typeof value === 'boolean') {\r\n return value\r\n }\r\n throw new InvalidError('not_a_boolean')\r\n}"],"mappings":"AAAA,OAAOA,YAAP,MAAyB,mBAAzB;AAEA,eAAe,SAASC,WAAT,CAAqBC,KAArB,EAA4B;EAC1C,IAAI,OAAOA,KAAP,KAAiB,SAArB,EAAgC;IAC7B,OAAOA,KAAP;EACD;;EACD,MAAM,IAAIF,YAAJ,CAAiB,eAAjB,CAAN;AACD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import parseDate from '../read/parseDate.js';
|
|
2
|
+
import InvalidError from './InvalidError.js';
|
|
3
|
+
export default function DateType(value, _ref) {
|
|
4
|
+
var properties = _ref.properties;
|
|
5
|
+
|
|
6
|
+
// XLSX has no specific format for dates.
|
|
7
|
+
// Sometimes a date can be heuristically detected.
|
|
8
|
+
// https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777
|
|
9
|
+
if (value instanceof Date) {
|
|
10
|
+
if (isNaN(value.valueOf())) {
|
|
11
|
+
throw new InvalidError('out_of_bounds');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (typeof value === 'number') {
|
|
18
|
+
if (isNaN(value)) {
|
|
19
|
+
throw new InvalidError('invalid_number');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (!isFinite(value)) {
|
|
23
|
+
throw new InvalidError('out_of_bounds');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var date = parseDate(value, properties);
|
|
27
|
+
|
|
28
|
+
if (isNaN(date.valueOf())) {
|
|
29
|
+
throw new InvalidError('out_of_bounds');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return date;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
throw new InvalidError('not_a_date');
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=Date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Date.js","names":["parseDate","InvalidError","DateType","value","properties","Date","isNaN","valueOf","isFinite","date"],"sources":["../../source/types/Date.js"],"sourcesContent":["import parseDate from '../read/parseDate.js'\r\nimport InvalidError from './InvalidError.js'\r\n\r\nexport default function DateType(value, { properties }) {\r\n\t// 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 throw new InvalidError('out_of_bounds')\r\n }\r\n return value\r\n }\r\n if (typeof value === 'number') {\r\n if (isNaN(value)) {\r\n throw new InvalidError('invalid_number')\r\n }\r\n if (!isFinite(value)) {\r\n throw new InvalidError('out_of_bounds')\r\n }\r\n const date = parseDate(value, properties)\r\n if (isNaN(date.valueOf())) {\r\n throw new InvalidError('out_of_bounds')\r\n }\r\n return date\r\n }\r\n throw new InvalidError('not_a_date')\r\n}"],"mappings":"AAAA,OAAOA,SAAP,MAAsB,sBAAtB;AACA,OAAOC,YAAP,MAAyB,mBAAzB;AAEA,eAAe,SAASC,QAAT,CAAkBC,KAAlB,QAAyC;EAAA,IAAdC,UAAc,QAAdA,UAAc;;EACvD;EACC;EACA;EACA,IAAID,KAAK,YAAYE,IAArB,EAA2B;IACzB,IAAIC,KAAK,CAACH,KAAK,CAACI,OAAN,EAAD,CAAT,EAA4B;MAC1B,MAAM,IAAIN,YAAJ,CAAiB,eAAjB,CAAN;IACD;;IACD,OAAOE,KAAP;EACD;;EACD,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;IAC7B,IAAIG,KAAK,CAACH,KAAD,CAAT,EAAkB;MAChB,MAAM,IAAIF,YAAJ,CAAiB,gBAAjB,CAAN;IACD;;IACD,IAAI,CAACO,QAAQ,CAACL,KAAD,CAAb,EAAsB;MACpB,MAAM,IAAIF,YAAJ,CAAiB,eAAjB,CAAN;IACD;;IACD,IAAMQ,IAAI,GAAGT,SAAS,CAACG,KAAD,EAAQC,UAAR,CAAtB;;IACA,IAAIE,KAAK,CAACG,IAAI,CAACF,OAAL,EAAD,CAAT,EAA2B;MACzB,MAAM,IAAIN,YAAJ,CAAiB,eAAjB,CAAN;IACD;;IACD,OAAOQ,IAAP;EACD;;EACD,MAAM,IAAIR,YAAJ,CAAiB,YAAjB,CAAN;AACD"}
|
package/modules/types/Email.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import InvalidError from './InvalidError.js';
|
|
2
|
+
export default function Email(value) {
|
|
3
|
+
if (typeof value === 'string') {
|
|
4
|
+
if (isEmail(value)) {
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
throw new InvalidError('not_an_email');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
throw new InvalidError('not_a_string');
|
|
12
|
+
}
|
|
2
13
|
var regexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
|
|
3
14
|
export function isEmail(value) {
|
|
4
15
|
return regexp.test(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Email.js","names":["Email","
|
|
1
|
+
{"version":3,"file":"Email.js","names":["InvalidError","Email","value","isEmail","regexp","test"],"sources":["../../source/types/Email.js"],"sourcesContent":["import InvalidError from './InvalidError.js'\r\n\r\nexport default function Email(value) {\r\n if (typeof value === 'string') {\r\n if (isEmail(value)) {\r\n return value\r\n }\r\n throw new InvalidError('not_an_email')\r\n }\r\n throw new InvalidError('not_a_string')\r\n}\r\n\r\nconst regexp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}$/i\r\n\r\nexport function isEmail(value) {\r\n\treturn regexp.test(value)\r\n}"],"mappings":"AAAA,OAAOA,YAAP,MAAyB,mBAAzB;AAEA,eAAe,SAASC,KAAT,CAAeC,KAAf,EAAsB;EACnC,IAAI,OAAOA,KAAP,KAAiB,QAArB,EAA+B;IAC7B,IAAIC,OAAO,CAACD,KAAD,CAAX,EAAoB;MAClB,OAAOA,KAAP;IACD;;IACD,MAAM,IAAIF,YAAJ,CAAiB,cAAjB,CAAN;EACD;;EACD,MAAM,IAAIA,YAAJ,CAAiB,cAAjB,CAAN;AACD;AAED,IAAMI,MAAM,GAAG,0CAAf;AAEA,OAAO,SAASD,OAAT,CAAiBD,KAAjB,EAAwB;EAC9B,OAAOE,MAAM,CAACC,IAAP,CAAYH,KAAZ,CAAP;AACA"}
|
package/modules/types/Integer.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import InvalidError from './InvalidError.js';
|
|
2
|
+
import NumberType from './Number.js';
|
|
3
|
+
export default function Integer(value) {
|
|
4
|
+
value = NumberType(value);
|
|
5
|
+
|
|
6
|
+
if (!isInteger(value)) {
|
|
7
|
+
throw new InvalidError('not_an_integer');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
2
12
|
export function isInteger(x) {
|
|
3
13
|
// https://stackoverflow.com/questions/14636536/how-to-check-if-a-variable-is-an-integer-in-javascript
|
|
4
14
|
return (x | 0) === x;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Integer.js","names":["Integer","isInteger","x"],"sources":["../../source/types/Integer.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"Integer.js","names":["InvalidError","NumberType","Integer","value","isInteger","x"],"sources":["../../source/types/Integer.js"],"sourcesContent":["import InvalidError from './InvalidError.js'\r\nimport NumberType from './Number.js'\r\n\r\nexport default function Integer(value) {\r\n\tvalue = NumberType(value)\r\n if (!isInteger(value)) {\r\n throw new InvalidError('not_an_integer')\r\n }\r\n return value\r\n}\r\n\r\nexport function isInteger(x) {\r\n\t// https://stackoverflow.com/questions/14636536/how-to-check-if-a-variable-is-an-integer-in-javascript\r\n\treturn (x | 0) === x\r\n}"],"mappings":"AAAA,OAAOA,YAAP,MAAyB,mBAAzB;AACA,OAAOC,UAAP,MAAuB,aAAvB;AAEA,eAAe,SAASC,OAAT,CAAiBC,KAAjB,EAAwB;EACtCA,KAAK,GAAGF,UAAU,CAACE,KAAD,CAAlB;;EACC,IAAI,CAACC,SAAS,CAACD,KAAD,CAAd,EAAuB;IACrB,MAAM,IAAIH,YAAJ,CAAiB,gBAAjB,CAAN;EACD;;EACD,OAAOG,KAAP;AACD;AAED,OAAO,SAASC,SAAT,CAAmBC,CAAnB,EAAsB;EAC5B;EACA,OAAO,CAACA,CAAC,GAAG,CAAL,MAAYA,CAAnB;AACA"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
|
|
3
|
+
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); } }
|
|
4
|
+
|
|
5
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
+
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
|
|
9
|
+
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); }
|
|
10
|
+
|
|
11
|
+
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); }; }
|
|
12
|
+
|
|
13
|
+
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); }
|
|
14
|
+
|
|
15
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
16
|
+
|
|
17
|
+
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
18
|
+
|
|
19
|
+
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); }
|
|
20
|
+
|
|
21
|
+
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; } }
|
|
22
|
+
|
|
23
|
+
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
24
|
+
|
|
25
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
26
|
+
|
|
27
|
+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
28
|
+
|
|
29
|
+
var InvalidError = /*#__PURE__*/function (_Error) {
|
|
30
|
+
_inherits(InvalidError, _Error);
|
|
31
|
+
|
|
32
|
+
var _super = _createSuper(InvalidError);
|
|
33
|
+
|
|
34
|
+
function InvalidError(reason) {
|
|
35
|
+
var _this;
|
|
36
|
+
|
|
37
|
+
_classCallCheck(this, InvalidError);
|
|
38
|
+
|
|
39
|
+
_this = _super.call(this, 'invalid');
|
|
40
|
+
_this.reason = reason;
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return _createClass(InvalidError);
|
|
45
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
46
|
+
|
|
47
|
+
export { InvalidError as default };
|
|
48
|
+
//# 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;;SAArBF,Y"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import InvalidError from './InvalidError.js';
|
|
2
|
+
export default function NumberType(value) {
|
|
3
|
+
// An XLSX file editing software might not always correctly
|
|
4
|
+
// detect numeric values in string-type cells. Users won't bother
|
|
5
|
+
// manually selecting a cell type, so the editing software has to guess
|
|
6
|
+
// based on the user's input. One can assume that such auto-detection
|
|
7
|
+
// might not always work.
|
|
8
|
+
//
|
|
9
|
+
// So, if a cell is supposed to be a numeric one, convert a string value to a number.
|
|
10
|
+
//
|
|
11
|
+
if (typeof value === 'string') {
|
|
12
|
+
var stringifiedValue = value;
|
|
13
|
+
value = Number(value);
|
|
14
|
+
|
|
15
|
+
if (String(value) !== stringifiedValue) {
|
|
16
|
+
throw new InvalidError('not_a_number');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (typeof value !== 'number') {
|
|
21
|
+
throw new InvalidError('not_a_number');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (isNaN(value)) {
|
|
25
|
+
throw new InvalidError('invalid_number');
|
|
26
|
+
} // At this point, `value` can only be a number.
|
|
27
|
+
//
|
|
28
|
+
// The global `isFinite()` function filters out:
|
|
29
|
+
// * NaN
|
|
30
|
+
// * -Infinity
|
|
31
|
+
// * Infinity
|
|
32
|
+
//
|
|
33
|
+
// All other values pass (including non-numbers).
|
|
34
|
+
//
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if (!isFinite(value)) {
|
|
38
|
+
throw new InvalidError('out_of_bounds');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=Number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Number.js","names":["InvalidError","NumberType","value","stringifiedValue","Number","String","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,OAAOA,YAAP,MAAyB,mBAAzB;AAEA,eAAe,SAASC,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,IAAIH,YAAJ,CAAiB,cAAjB,CAAN;IACD;EACF;;EACD,IAAI,OAAOE,KAAP,KAAiB,QAArB,EAA+B;IAC7B,MAAM,IAAIF,YAAJ,CAAiB,cAAjB,CAAN;EACD;;EACD,IAAIM,KAAK,CAACJ,KAAD,CAAT,EAAkB;IAChB,MAAM,IAAIF,YAAJ,CAAiB,gBAAjB,CAAN;EACD,CArBuC,CAsBxC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;EACA,IAAI,CAACO,QAAQ,CAACL,KAAD,CAAb,EAAsB;IACpB,MAAM,IAAIF,YAAJ,CAAiB,eAAjB,CAAN;EACD;;EACD,OAAOE,KAAP;AACD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import InvalidError from './InvalidError.js';
|
|
2
|
+
export default function StringType(value) {
|
|
3
|
+
if (typeof value === 'string') {
|
|
4
|
+
return value;
|
|
5
|
+
} // Excel tends to perform a forced automatic convertion of string-type values
|
|
6
|
+
// to number-type ones when the user has input them. Otherwise, users wouldn't
|
|
7
|
+
// be able to perform formula calculations on those cell values because users
|
|
8
|
+
// won't bother manually choosing a "numeric" cell type for each cell, and
|
|
9
|
+
// even if they did, choosing a "numeric" cell type every time wouldn't be an
|
|
10
|
+
// acceptable "user experience".
|
|
11
|
+
//
|
|
12
|
+
// So, if a cell value is supposed to be a string and Excel has automatically
|
|
13
|
+
// converted it to a number, perform a backwards conversion.
|
|
14
|
+
//
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
if (typeof value === 'number') {
|
|
18
|
+
if (isNaN(value)) {
|
|
19
|
+
throw new InvalidError('invalid_number');
|
|
20
|
+
} // The global `isFinite()` function filters out:
|
|
21
|
+
// * NaN
|
|
22
|
+
// * -Infinity
|
|
23
|
+
// * Infinity
|
|
24
|
+
//
|
|
25
|
+
// All other values pass (including non-numbers).
|
|
26
|
+
//
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
if (!isFinite(value)) {
|
|
30
|
+
throw new InvalidError('out_of_bounds');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return String(value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
throw new InvalidError('not_a_string');
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=String.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"String.js","names":["InvalidError","StringType","value","isNaN","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,OAAOA,YAAP,MAAyB,mBAAzB;AAEA,eAAe,SAASC,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,IAAIF,YAAJ,CAAiB,gBAAjB,CAAN;IACD,CAH4B,CAI7B;IACA;IACA;IACA;IACA;IACA;IACA;;;IACA,IAAI,CAACI,QAAQ,CAACF,KAAD,CAAb,EAAsB;MACpB,MAAM,IAAIF,YAAJ,CAAiB,eAAjB,CAAN;IACD;;IACD,OAAOK,MAAM,CAACH,KAAD,CAAb;EACD;;EACD,MAAM,IAAIF,YAAJ,CAAiB,cAAjB,CAAN;AACD"}
|
package/modules/types/URL.js
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import InvalidError from './InvalidError.js';
|
|
2
|
+
export default function URL(value) {
|
|
3
|
+
if (typeof value === 'string') {
|
|
4
|
+
if (isURL(value)) {
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
throw new InvalidError('not_a_url');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
throw new InvalidError('not_a_string');
|
|
12
|
+
} // URL regexp explanation:
|
|
2
13
|
//
|
|
3
14
|
// /^
|
|
4
15
|
//
|
package/modules/types/URL.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"URL.js","names":["URL","
|
|
1
|
+
{"version":3,"file":"URL.js","names":["InvalidError","URL","value","isURL","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,OAAOA,YAAP,MAAyB,mBAAzB;AAEA,eAAe,SAASC,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,IAAIF,YAAJ,CAAiB,WAAjB,CAAN;EACD;;EACD,MAAM,IAAIA,YAAJ,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,IAAMI,MAAM,GAAG,+RAAf,C,CAEA;;AACA,OAAO,SAASD,KAAT,CAAeD,KAAf,EAAsB;EAC5B,OAAOE,MAAM,CAACC,IAAP,CAAYH,KAAZ,CAAP;AACA"}
|
package/package.json
CHANGED
package/web-worker/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export {
|
|
|
16
16
|
|
|
17
17
|
export function parseExcelDate(excelSerialDate: number) : typeof Date;
|
|
18
18
|
|
|
19
|
-
type Input = File | ArrayBuffer;
|
|
19
|
+
type Input = File | Blob | ArrayBuffer;
|
|
20
20
|
|
|
21
21
|
export function readXlsxFile<T extends object>(input: Input, options: ParseWithSchemaOptions<T>) : Promise<ParsedObjectsResult<T>>;
|
|
22
22
|
export function readXlsxFile<T extends object>(input: Input, options: ParseWithMapOptions) : Promise<ParsedObjectsResult<T>>;
|