read-excel-file 5.3.2 → 5.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +73 -32
  3. package/bundle/read-excel-file.min.js +1 -1
  4. package/bundle/read-excel-file.min.js.map +1 -1
  5. package/commonjs/read/isDateTimestamp.js +112 -0
  6. package/commonjs/read/isDateTimestamp.js.map +1 -0
  7. package/commonjs/read/parseCell.js +5 -0
  8. package/commonjs/read/parseCell.js.map +1 -1
  9. package/commonjs/read/parseCellValue.js +78 -93
  10. package/commonjs/read/parseCellValue.js.map +1 -1
  11. package/commonjs/read/parseDate.js.map +1 -1
  12. package/commonjs/read/schema/convertToJson.js +99 -31
  13. package/commonjs/read/schema/convertToJson.js.map +1 -1
  14. package/commonjs/read/schema/convertToJson.test.js.map +1 -1
  15. package/commonjs/xml/dom.js +29 -0
  16. package/commonjs/xml/dom.js.map +1 -1
  17. package/commonjs/xml/xlsx.js.map +1 -1
  18. package/commonjs/xml/xml.js +2 -4
  19. package/commonjs/xml/xml.js.map +1 -1
  20. package/commonjs/xml/{xlsx-xpath.js → xpath/xlsx-xpath.js} +1 -0
  21. package/commonjs/xml/xpath/xlsx-xpath.js.map +1 -0
  22. package/commonjs/xml/{xpathBrowser.js → xpath/xpathBrowser.js} +1 -0
  23. package/commonjs/xml/xpath/xpathBrowser.js.map +1 -0
  24. package/commonjs/xml/{xpathNode.js → xpath/xpathNode.js} +1 -1
  25. package/commonjs/xml/xpath/xpathNode.js.map +1 -0
  26. package/modules/read/isDateTimestamp.js +104 -0
  27. package/modules/read/isDateTimestamp.js.map +1 -0
  28. package/modules/read/parseCell.js +5 -1
  29. package/modules/read/parseCell.js.map +1 -1
  30. package/modules/read/parseCellValue.js +76 -91
  31. package/modules/read/parseCellValue.js.map +1 -1
  32. package/modules/read/parseDate.js.map +1 -1
  33. package/modules/read/schema/convertToJson.js +99 -31
  34. package/modules/read/schema/convertToJson.js.map +1 -1
  35. package/modules/read/schema/convertToJson.test.js.map +1 -1
  36. package/modules/xml/dom.js +27 -0
  37. package/modules/xml/dom.js.map +1 -1
  38. package/modules/xml/xlsx.js.map +1 -1
  39. package/modules/xml/xml.js +2 -2
  40. package/modules/xml/xml.js.map +1 -1
  41. package/modules/xml/{xlsx-xpath.js → xpath/xlsx-xpath.js} +1 -0
  42. package/modules/xml/xpath/xlsx-xpath.js.map +1 -0
  43. package/modules/xml/{xpathBrowser.js → xpath/xpathBrowser.js} +1 -0
  44. package/modules/xml/xpath/xpathBrowser.js.map +1 -0
  45. package/modules/xml/{xpathNode.js → xpath/xpathNode.js} +1 -1
  46. package/modules/xml/xpath/xpathNode.js.map +1 -0
  47. package/package.json +1 -1
  48. package/types.d.ts +11 -6
  49. package/commonjs/xml/xlsx-xpath.js.map +0 -1
  50. package/commonjs/xml/xpathBrowser.js.map +0 -1
  51. package/commonjs/xml/xpathNode.js.map +0 -1
  52. package/modules/xml/xlsx-xpath.js.map +0 -1
  53. package/modules/xml/xpathBrowser.js.map +0 -1
  54. package/modules/xml/xpathNode.js.map +0 -1
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = isDateTimestamp;
7
+
8
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+
12
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
13
+
14
+ // XLSX does have "d" type for dates, but it's not commonly used.
15
+ // Instead, it prefers using "n" type for storing dates as timestamps.
16
+ //
17
+ // Whether a numeric value is a number or a date timestamp, it sometimes could be
18
+ // detected by looking at the value "format" and seeing if it's a date-specific one.
19
+ // https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777
20
+ //
21
+ // The list of generic numeric value "formats":
22
+ // https://xlsxwriter.readthedocs.io/format.html#format-set-num-format
23
+ //
24
+ function isDateTimestamp(value, styleId, styles, options) {
25
+ if (styleId) {
26
+ var style = styles[styleId];
27
+
28
+ if (!style) {
29
+ throw new Error("Cell style not found: ".concat(styleId));
30
+ }
31
+
32
+ if ( // Whether it's a "number format" that's conventionally used for storing date timestamps.
33
+ BUILT_IN_DATE_NUMBER_FORMAT_IDS.indexOf(parseInt(style.numberFormat.id)) >= 0 || // Whether it's a "number format" that uses a "formatting template"
34
+ // that the developer is certain is a date formatting template.
35
+ options.dateFormat && style.numberFormat.template === options.dateFormat || // Whether the "smart formatting template" feature is not disabled
36
+ // and it has detected that it's a date formatting template by looking at it.
37
+ options.smartDateParser !== false && style.numberFormat.template && isDateTemplate(style.numberFormat.template)) {
38
+ return true;
39
+ }
40
+ }
41
+ } // https://hexdocs.pm/xlsxir/number_styles.html
42
+
43
+
44
+ var BUILT_IN_DATE_NUMBER_FORMAT_IDS = [14, 15, 16, 17, 18, 19, 20, 21, 22, 27, 30, 36, 45, 46, 47, 50, 57]; // On some date formats, there's an "[$-414]" prefix.
45
+ // I don't have any idea what that is.
46
+ //
47
+ // https://stackoverflow.com/questions/4730152/what-indicates-an-office-open-xml-cell-contains-a-date-time-value
48
+ //
49
+ // Examples:
50
+ //
51
+ // * 27 (built-in format) "[$-404]e/m/d"
52
+ // * 164 (custom format) "[$-414]mmmm\ yyyy;@"
53
+ //
54
+
55
+ var DATE_FORMAT_WEIRD_PREFIX = /^\[\$-414\]/; // On some date formats, there's an ";@" postfix.
56
+ // I don't have any idea what that is.
57
+ // Examples:
58
+ //
59
+ // * 164 (custom format) "m/d/yyyy;@"
60
+ // * 164 (custom format) "[$-414]mmmm\ yyyy;@"
61
+ //
62
+
63
+ var DATE_FORMAT_WEIRD_POSTFIX = /;@$/;
64
+
65
+ function isDateTemplate(template) {
66
+ // Date format tokens could be in upper case or in lower case.
67
+ // There seems to be no single standard.
68
+ // So lowercase the template first.
69
+ template = template.toLowerCase(); // On some date formats, there's an "[$-414]" prefix.
70
+ // I don't have any idea what that is. Trim it.
71
+
72
+ template = template.replace(DATE_FORMAT_WEIRD_PREFIX, ''); // On some date formats, there's an ";@" postfix.
73
+ // I don't have any idea what that is. Trim it.
74
+
75
+ template = template.replace(DATE_FORMAT_WEIRD_POSTFIX, '');
76
+ var tokens = template.split(/\W+/);
77
+
78
+ for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) {
79
+ var token = _step.value;
80
+
81
+ if (DATE_TEMPLATE_TOKENS.indexOf(token) < 0) {
82
+ return false;
83
+ }
84
+ }
85
+
86
+ return true;
87
+ } // These tokens could be in upper case or in lower case.
88
+ // There seems to be no single standard, so using lower case.
89
+
90
+
91
+ var DATE_TEMPLATE_TOKENS = [// Seconds (min two digits). Example: "05".
92
+ 'ss', // Minutes (min two digits). Example: "05". Could also be "Months". Weird.
93
+ 'mm', // Hours. Example: "1".
94
+ 'h', // Hours (min two digits). Example: "01".
95
+ 'hh', // "AM" part of "AM/PM". Lowercased just in case.
96
+ 'am', // "PM" part of "AM/PM". Lowercased just in case.
97
+ 'pm', // Day. Example: "1"
98
+ 'd', // Day (min two digits). Example: "01"
99
+ 'dd', // Month (numeric). Example: "1".
100
+ 'm', // Month (numeric, min two digits). Example: "01". Could also be "Minutes". Weird.
101
+ 'mm', // Month (shortened month name). Example: "Jan".
102
+ 'mmm', // Month (full month name). Example: "January".
103
+ 'mmmm', // Two-digit year. Example: "20".
104
+ 'yy', // Full year. Example: "2020".
105
+ 'yyyy', // I don't have any idea what "e" means.
106
+ // It's used in "built-in" XLSX formats:
107
+ // * 27 '[$-404]e/m/d';
108
+ // * 36 '[$-404]e/m/d';
109
+ // * 50 '[$-404]e/m/d';
110
+ // * 57 '[$-404]e/m/d';
111
+ 'e'];
112
+ //# sourceMappingURL=isDateTimestamp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isDateTimestamp.js","names":["isDateTimestamp","value","styleId","styles","options","style","Error","BUILT_IN_DATE_NUMBER_FORMAT_IDS","indexOf","parseInt","numberFormat","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 (\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(parseInt(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;AACe,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,KACE;IACAK,+BAA+B,CAACC,OAAhC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IC,oBAAoB,CAACf,OAArB,CAA6Bc,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"}
@@ -11,6 +11,8 @@ var _coordinates = require("./coordinates.js");
11
11
 
12
12
  var _xlsx = require("../xml/xlsx.js");
13
13
 
14
+ var _dom = require("../xml/dom.js");
15
+
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
17
 
16
18
  // Example of a `<c/>`ell element:
@@ -58,6 +60,9 @@ function parseCell(node, sheet, xml, values, styles, properties, options) {
58
60
  getInlineStringValue: function getInlineStringValue() {
59
61
  return (0, _xlsx.getCellInlineStringValue)(sheet, node);
60
62
  },
63
+ getInlineStringXml: function getInlineStringXml() {
64
+ return (0, _dom.getOuterXml)(node);
65
+ },
61
66
  getStyleId: function getStyleId() {
62
67
  return node.getAttribute('s');
63
68
  },
@@ -1 +1 @@
1
- {"version":3,"file":"parseCell.js","names":["parseCell","node","sheet","xml","values","styles","properties","options","coords","parseCellCoordinates","getAttribute","valueElement","getCellValue","value","textContent","type","hasAttribute","row","column","parseCellValue","getInlineStringValue","getCellInlineStringValue","getStyleId"],"sources":["../../source/read/parseCell.js"],"sourcesContent":["import parseCellValue from './parseCellValue.js'\r\n\r\nimport {\r\n parseCellCoordinates\r\n} from './coordinates.js'\r\n\r\nimport {\r\n getCellValue,\r\n getCellInlineStringValue\r\n} from '../xml/xlsx.js'\r\n\r\n// Example of a `<c/>`ell element:\r\n//\r\n// <c>\r\n// <f>string</f> — formula.\r\n// <v>string</v> — formula pre-computed value.\r\n// <is>\r\n// <t>string</t> — an `inlineStr` string (rather than a \"common string\" from a dictionary).\r\n// <r>\r\n// <rPr>\r\n// ...\r\n// </rPr>\r\n// <t>string</t>\r\n// </r>\r\n// <rPh sb=\"1\" eb=\"1\">\r\n// <t>string</t>\r\n// </rPh>\r\n// <phoneticPr fontId=\"1\"/>\r\n// </is>\r\n// <extLst>\r\n// <ext>\r\n// <!--any element-->\r\n// </ext>\r\n// </extLst>\r\n// </c>\r\n//\r\nexport default function parseCell(node, sheet, xml, values, styles, properties, options) {\r\n const coords = parseCellCoordinates(node.getAttribute('r'))\r\n\r\n const valueElement = getCellValue(sheet, node)\r\n\r\n // For `xpath`, `value` can be `undefined` while for native `DOMParser` it's `null`.\r\n // So using `value && ...` instead of `if (value !== undefined) { ... }` here\r\n // for uniform compatibility with both `xpath` and native `DOMParser`.\r\n let value = valueElement && valueElement.textContent\r\n\r\n let type\r\n if (node.hasAttribute('t')) {\r\n type = node.getAttribute('t')\r\n }\r\n\r\n return {\r\n row: coords[0],\r\n column: coords[1],\r\n value: parseCellValue(value, type, {\r\n getInlineStringValue: () => getCellInlineStringValue(sheet, node),\r\n getStyleId: () => node.getAttribute('s'),\r\n styles,\r\n values,\r\n properties,\r\n options\r\n })\r\n }\r\n}"],"mappings":";;;;;;;AAAA;;AAEA;;AAIA;;;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,SAAT,CAAmBC,IAAnB,EAAyBC,KAAzB,EAAgCC,GAAhC,EAAqCC,MAArC,EAA6CC,MAA7C,EAAqDC,UAArD,EAAiEC,OAAjE,EAA0E;EACvF,IAAMC,MAAM,GAAG,IAAAC,iCAAA,EAAqBR,IAAI,CAACS,YAAL,CAAkB,GAAlB,CAArB,CAAf;EAEA,IAAMC,YAAY,GAAG,IAAAC,kBAAA,EAAaV,KAAb,EAAoBD,IAApB,CAArB,CAHuF,CAKvF;EACA;EACA;;EACA,IAAIY,KAAK,GAAGF,YAAY,IAAIA,YAAY,CAACG,WAAzC;EAEA,IAAIC,IAAJ;;EACA,IAAId,IAAI,CAACe,YAAL,CAAkB,GAAlB,CAAJ,EAA4B;IAC1BD,IAAI,GAAGd,IAAI,CAACS,YAAL,CAAkB,GAAlB,CAAP;EACD;;EAED,OAAO;IACLO,GAAG,EAAET,MAAM,CAAC,CAAD,CADN;IAELU,MAAM,EAAEV,MAAM,CAAC,CAAD,CAFT;IAGLK,KAAK,EAAE,IAAAM,0BAAA,EAAeN,KAAf,EAAsBE,IAAtB,EAA4B;MACjCK,oBAAoB,EAAE;QAAA,OAAM,IAAAC,8BAAA,EAAyBnB,KAAzB,EAAgCD,IAAhC,CAAN;MAAA,CADW;MAEjCqB,UAAU,EAAE;QAAA,OAAMrB,IAAI,CAACS,YAAL,CAAkB,GAAlB,CAAN;MAAA,CAFqB;MAGjCL,MAAM,EAANA,MAHiC;MAIjCD,MAAM,EAANA,MAJiC;MAKjCE,UAAU,EAAVA,UALiC;MAMjCC,OAAO,EAAPA;IANiC,CAA5B;EAHF,CAAP;AAYD"}
1
+ {"version":3,"file":"parseCell.js","names":["parseCell","node","sheet","xml","values","styles","properties","options","coords","parseCellCoordinates","getAttribute","valueElement","getCellValue","value","textContent","type","hasAttribute","row","column","parseCellValue","getInlineStringValue","getCellInlineStringValue","getInlineStringXml","getOuterXml","getStyleId"],"sources":["../../source/read/parseCell.js"],"sourcesContent":["import parseCellValue from './parseCellValue.js'\r\n\r\nimport {\r\n parseCellCoordinates\r\n} from './coordinates.js'\r\n\r\nimport {\r\n getCellValue,\r\n getCellInlineStringValue\r\n} from '../xml/xlsx.js'\r\n\r\nimport {\r\n getOuterXml\r\n} from '../xml/dom.js'\r\n\r\n// Example of a `<c/>`ell element:\r\n//\r\n// <c>\r\n// <f>string</f> — formula.\r\n// <v>string</v> — formula pre-computed value.\r\n// <is>\r\n// <t>string</t> — an `inlineStr` string (rather than a \"common string\" from a dictionary).\r\n// <r>\r\n// <rPr>\r\n// ...\r\n// </rPr>\r\n// <t>string</t>\r\n// </r>\r\n// <rPh sb=\"1\" eb=\"1\">\r\n// <t>string</t>\r\n// </rPh>\r\n// <phoneticPr fontId=\"1\"/>\r\n// </is>\r\n// <extLst>\r\n// <ext>\r\n// <!--any element-->\r\n// </ext>\r\n// </extLst>\r\n// </c>\r\n//\r\nexport default function parseCell(node, sheet, xml, values, styles, properties, options) {\r\n const coords = parseCellCoordinates(node.getAttribute('r'))\r\n\r\n const valueElement = getCellValue(sheet, node)\r\n\r\n // For `xpath`, `value` can be `undefined` while for native `DOMParser` it's `null`.\r\n // So using `value && ...` instead of `if (value !== undefined) { ... }` here\r\n // for uniform compatibility with both `xpath` and native `DOMParser`.\r\n let value = valueElement && valueElement.textContent\r\n\r\n let type\r\n if (node.hasAttribute('t')) {\r\n type = node.getAttribute('t')\r\n }\r\n\r\n return {\r\n row: coords[0],\r\n column: coords[1],\r\n value: parseCellValue(value, type, {\r\n getInlineStringValue: () => getCellInlineStringValue(sheet, node),\r\n getInlineStringXml: () => getOuterXml(node),\r\n getStyleId: () => node.getAttribute('s'),\r\n styles,\r\n values,\r\n properties,\r\n options\r\n })\r\n }\r\n}"],"mappings":";;;;;;;AAAA;;AAEA;;AAIA;;AAKA;;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,SAAT,CAAmBC,IAAnB,EAAyBC,KAAzB,EAAgCC,GAAhC,EAAqCC,MAArC,EAA6CC,MAA7C,EAAqDC,UAArD,EAAiEC,OAAjE,EAA0E;EACvF,IAAMC,MAAM,GAAG,IAAAC,iCAAA,EAAqBR,IAAI,CAACS,YAAL,CAAkB,GAAlB,CAArB,CAAf;EAEA,IAAMC,YAAY,GAAG,IAAAC,kBAAA,EAAaV,KAAb,EAAoBD,IAApB,CAArB,CAHuF,CAKvF;EACA;EACA;;EACA,IAAIY,KAAK,GAAGF,YAAY,IAAIA,YAAY,CAACG,WAAzC;EAEA,IAAIC,IAAJ;;EACA,IAAId,IAAI,CAACe,YAAL,CAAkB,GAAlB,CAAJ,EAA4B;IAC1BD,IAAI,GAAGd,IAAI,CAACS,YAAL,CAAkB,GAAlB,CAAP;EACD;;EAED,OAAO;IACLO,GAAG,EAAET,MAAM,CAAC,CAAD,CADN;IAELU,MAAM,EAAEV,MAAM,CAAC,CAAD,CAFT;IAGLK,KAAK,EAAE,IAAAM,0BAAA,EAAeN,KAAf,EAAsBE,IAAtB,EAA4B;MACjCK,oBAAoB,EAAE;QAAA,OAAM,IAAAC,8BAAA,EAAyBnB,KAAzB,EAAgCD,IAAhC,CAAN;MAAA,CADW;MAEjCqB,kBAAkB,EAAE;QAAA,OAAM,IAAAC,gBAAA,EAAYtB,IAAZ,CAAN;MAAA,CAFa;MAGjCuB,UAAU,EAAE;QAAA,OAAMvB,IAAI,CAACS,YAAL,CAAkB,GAAlB,CAAN;MAAA,CAHqB;MAIjCL,MAAM,EAANA,MAJiC;MAKjCD,MAAM,EAANA,MALiC;MAMjCE,UAAU,EAAVA,UANiC;MAOjCC,OAAO,EAAPA;IAPiC,CAA5B;EAHF,CAAP;AAaD"}
@@ -3,23 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports["default"] = getCellValue;
6
+ exports["default"] = parseCellValue;
7
7
 
8
8
  var _parseDate = _interopRequireDefault(require("./parseDate.js"));
9
9
 
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
11
-
12
- function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
-
14
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
-
16
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
10
+ var _isDateTimestamp = _interopRequireDefault(require("./isDateTimestamp.js"));
17
11
 
18
- // https://hexdocs.pm/xlsxir/number_styles.html
19
- var BUILT_IN_DATE_NUMBER_FORMAT_IDS = [14, 15, 16, 17, 18, 19, 20, 21, 22, 27, 30, 36, 45, 46, 47, 50, 57];
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
20
13
 
21
- function getCellValue(value, type, _ref) {
14
+ // Parses a string `value` of a cell.
15
+ function parseCellValue(value, type, _ref) {
22
16
  var getInlineStringValue = _ref.getInlineStringValue,
17
+ getInlineStringXml = _ref.getInlineStringXml,
23
18
  getStyleId = _ref.getStyleId,
24
19
  styles = _ref.styles,
25
20
  values = _ref.values,
@@ -39,105 +34,115 @@ function getCellValue(value, type, _ref) {
39
34
 
40
35
 
41
36
  switch (type) {
42
- // If the cell contains formula string.
37
+ // XLSX tends to store all strings as "shared" (indexed) ones
38
+ // using "s" cell type (for saving on strage space).
39
+ // "str" cell type is then generally only used for storing
40
+ // formula-pre-calculated cell values.
43
41
  case 'str':
44
- value = value.trim();
45
-
46
- if (value === '') {
47
- value = undefined;
48
- }
49
-
42
+ value = parseString(value, options);
50
43
  break;
51
- // If the cell contains an "inline" (not "shared") string.
44
+ // Sometimes, XLSX stores strings as "inline" strings rather than "shared" (indexed) ones.
45
+ // Perhaps the specification doesn't force it to use one or another.
46
+ // Example: `<sheetData><row r="1"><c r="A1" s="1" t="inlineStr"><is><t>Test 123</t></is></c></row></sheetData>`.
52
47
 
53
48
  case 'inlineStr':
54
49
  value = getInlineStringValue();
55
50
 
56
51
  if (value === undefined) {
57
- throw new Error("Unsupported \"inline string\" cell value structure"); // : ${cellNode.textContent}`)
58
- }
59
-
60
- value = value.trim();
61
-
62
- if (value === '') {
63
- value = undefined;
52
+ throw new Error("Unsupported \"inline string\" cell value structure: ".concat(getInlineStringXml()));
64
53
  }
65
54
 
55
+ value = parseString(value, options);
66
56
  break;
67
- // If the cell contains a "shared" string.
57
+ // XLSX tends to store string values as "shared" (indexed) ones.
68
58
  // "Shared" strings is a way for an Excel editor to reduce
69
59
  // the file size by storing "commonly used" strings in a dictionary
70
60
  // and then referring to such strings by their index in that dictionary.
61
+ // Example: `<sheetData><row r="1"><c r="A1" s="1" t="s"><v>0</v></c></row></sheetData>`.
71
62
 
72
63
  case 's':
73
64
  // If a cell has no value then there's no `<c/>` element for it.
74
65
  // If a `<c/>` element exists then it's not empty.
75
66
  // The `<v/>`alue is a key in the "shared strings" dictionary of the
76
67
  // XLSX file, so look it up in the `values` dictionary by the numeric key.
77
- value = values[parseInt(value)];
78
- value = value.trim();
68
+ var sharedStringIndex = Number(value);
69
+
70
+ if (isNaN(sharedStringIndex)) {
71
+ throw new Error("Invalid \"shared\" string index: ".concat(value));
72
+ }
79
73
 
80
- if (value === '') {
81
- value = undefined;
74
+ if (sharedStringIndex >= values.length) {
75
+ throw new Error("An out-of-bounds \"shared\" string index: ".concat(value));
82
76
  }
83
77
 
78
+ value = values[sharedStringIndex];
79
+ value = parseString(value, options);
84
80
  break;
81
+ // Boolean (TRUE/FALSE) values are stored as either "1" or "0"
82
+ // in cells of type "b".
85
83
 
86
84
  case 'b':
87
- value = value === '1' ? true : false;
85
+ if (value === '1') {
86
+ value = true;
87
+ } else if (value === '0') {
88
+ value = false;
89
+ } else {
90
+ throw new Error("Unsupported \"boolean\" cell value: ".concat(value));
91
+ }
92
+
88
93
  break;
89
- // Stub: blank stub cell that is ignored by data processing utilities.
94
+ // XLSX specification seems to support cells of type "z":
95
+ // blank "stub" cells that should be ignored by data processing utilities.
90
96
 
91
97
  case 'z':
92
98
  value = undefined;
93
99
  break;
94
- // Error: `value` is a numeric code.
100
+ // XLSX specification also defines cells of type "e" containing a numeric "error" code.
101
+ // It's not clear what that means though.
95
102
  // They also wrote: "and `w` property stores its common name".
96
103
  // It's unclear what they meant by that.
97
104
 
98
105
  case 'e':
99
106
  value = decodeError(value);
100
107
  break;
101
- // Date: a string to be parsed as a date.
102
- // (usually a string in "ISO 8601" format)
108
+ // XLSX supports date cells of type "d", though seems like it (almost?) never
109
+ // uses it for storing dates, preferring "n" numeric timestamp cells instead.
110
+ // The value of a "d" cell is supposedly a string in "ISO 8601" format.
111
+ // I haven't seen an XLSX file having such cells.
112
+ // Example: `<sheetData><row r="1"><c r="A1" s="1" t="d"><v>2021-06-10T00:47:45.700Z</v></c></row></sheetData>`.
103
113
 
104
114
  case 'd':
105
115
  if (value === undefined) {
106
116
  break;
107
117
  }
108
118
 
109
- value = new Date(value);
119
+ var parsedDate = new Date(value);
120
+
121
+ if (isNaN(parsedDate)) {
122
+ throw new Error("Unsupported \"date\" cell value: ".concat(value));
123
+ }
124
+
125
+ value = parsedDate;
110
126
  break;
127
+ // Numeric cells have type "n".
111
128
 
112
129
  case 'n':
113
130
  if (value === undefined) {
114
131
  break;
115
132
  }
116
133
 
117
- value = parseFloat(value); // XLSX does have "d" type for dates, but it's not commonly used.
118
- // Instead, spreadsheets prefer using "n" type for dates for some reason.
119
- //
120
- // In such cases, sometimes a "date" type could be heuristically detected
121
- // by looking at such numeric value "format" and seeing if it's a date-specific one.
122
- // https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777
123
- //
124
- // The list of generic numeric value "formats":
125
- // https://xlsxwriter.readthedocs.io/format.html#format-set-num-format
126
- //
127
-
128
- var styleId = getStyleId();
129
-
130
- if (styleId) {
131
- // styleId = parseInt(styleId)
132
- var style = styles[styleId];
133
-
134
- if (!style) {
135
- throw new Error("Cell style not found: ".concat(styleId));
136
- }
137
-
138
- if (BUILT_IN_DATE_NUMBER_FORMAT_IDS.indexOf(parseInt(style.numberFormat.id)) >= 0 || options.dateFormat && style.numberFormat.template === options.dateFormat || options.smartDateParser !== false && style.numberFormat.template && isDateTemplate(style.numberFormat.template)) {
139
- value = (0, _parseDate["default"])(value, properties);
140
- }
134
+ var parsedNumber = Number(value);
135
+
136
+ if (isNaN(parsedNumber)) {
137
+ throw new Error("Invalid \"numeric\" cell value: ".concat(value));
138
+ }
139
+
140
+ value = parsedNumber; // XLSX does have "d" type for dates, but it's not commonly used.
141
+ // Instead, it prefers using "n" type for storing dates as timestamps.
142
+
143
+ if ((0, _isDateTimestamp["default"])(value, getStyleId(), styles, options)) {
144
+ // Parse the number as a date timestamp.
145
+ value = (0, _parseDate["default"])(value, properties);
141
146
  }
142
147
 
143
148
  break;
@@ -190,39 +195,19 @@ function decodeError(errorCode) {
190
195
  }
191
196
  }
192
197
 
193
- function isDateTemplate(template) {
194
- // Date format tokens could be in upper case or in lower case.
195
- // There seems to be no single standard.
196
- // So lowercase the template first.
197
- template = template.toLowerCase();
198
- var tokens = template.split(/\W+/);
199
-
200
- for (var _iterator = _createForOfIteratorHelperLoose(tokens), _step; !(_step = _iterator()).done;) {
201
- var token = _step.value;
198
+ function parseString(value, options) {
199
+ // In some weird cases, a developer might want to disable
200
+ // the automatic trimming of all strings.
201
+ // For example, leading spaces might express a tree-like hierarchy.
202
+ // https://github.com/catamphetamine/read-excel-file/pull/106#issuecomment-1136062917
203
+ if (options.trim !== false) {
204
+ value = value.trim();
205
+ }
202
206
 
203
- if (DATE_TEMPLATE_TOKENS.indexOf(token) < 0) {
204
- return false;
205
- }
207
+ if (value === '') {
208
+ value = undefined;
206
209
  }
207
210
 
208
- return true;
209
- } // These tokens could be in upper case or in lower case.
210
- // There seems to be no single standard, so using lower case.
211
-
212
-
213
- var DATE_TEMPLATE_TOKENS = [// Seconds (min two digits). Example: "05".
214
- 'ss', // Minutes (min two digits). Example: "05". Could also be "Months". Weird.
215
- 'mm', // Hours. Example: "1".
216
- 'h', // Hours (min two digits). Example: "01".
217
- 'hh', // "AM" part of "AM/PM". Lowercased just in case.
218
- 'am', // "PM" part of "AM/PM". Lowercased just in case.
219
- 'pm', // Day. Example: "1"
220
- 'd', // Day (min two digits). Example: "01"
221
- 'dd', // Month (numeric). Example: "1".
222
- 'm', // Month (numeric, min two digits). Example: "01". Could also be "Minutes". Weird.
223
- 'mm', // Month (shortened month name). Example: "Jan".
224
- 'mmm', // Month (full month name). Example: "January".
225
- 'mmmm', // Two-digit year. Example: "20".
226
- 'yy', // Full year. Example: "2020".
227
- 'yyyy'];
211
+ return value;
212
+ }
228
213
  //# sourceMappingURL=parseCellValue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseCellValue.js","names":["BUILT_IN_DATE_NUMBER_FORMAT_IDS","getCellValue","value","type","getInlineStringValue","getStyleId","styles","values","properties","options","trim","undefined","Error","parseInt","decodeError","Date","parseFloat","styleId","style","indexOf","numberFormat","id","dateFormat","template","smartDateParser","isDateTemplate","parseDate","TypeError","errorCode","toLowerCase","tokens","split","token","DATE_TEMPLATE_TOKENS"],"sources":["../../source/read/parseCellValue.js"],"sourcesContent":["import parseDate from './parseDate.js'\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\nexport default function getCellValue(value, type, {\r\n\tgetInlineStringValue,\r\n\tgetStyleId,\r\n\tstyles,\r\n\tvalues,\r\n\tproperties,\r\n\toptions\r\n}) {\r\n if (!type) {\r\n // Default cell type is \"n\" (numeric).\r\n // http://www.datypic.com/sc/ooxml/t-ssml_CT_Cell.html\r\n type = 'n'\r\n }\r\n\r\n // Available Excel cell types:\r\n // https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md\r\n //\r\n // Some other document (seems to be old):\r\n // http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/ST_CellType.html\r\n //\r\n switch (type) {\r\n // If the cell contains formula string.\r\n case 'str':\r\n value = value.trim()\r\n if (value === '') {\r\n value = undefined\r\n }\r\n break\r\n\r\n // If the cell contains an \"inline\" (not \"shared\") string.\r\n case 'inlineStr':\r\n value = getInlineStringValue()\r\n if (value === undefined) {\r\n throw new Error(`Unsupported \"inline string\" cell value structure`) // : ${cellNode.textContent}`)\r\n }\r\n value = value.trim()\r\n if (value === '') {\r\n value = undefined\r\n }\r\n break\r\n\r\n // If the cell contains a \"shared\" string.\r\n // \"Shared\" strings is a way for an Excel editor to reduce\r\n // the file size by storing \"commonly used\" strings in a dictionary\r\n // and then referring to such strings by their index in that dictionary.\r\n case 's':\r\n // If a cell has no value then there's no `<c/>` element for it.\r\n // If a `<c/>` element exists then it's not empty.\r\n // The `<v/>`alue is a key in the \"shared strings\" dictionary of the\r\n // XLSX file, so look it up in the `values` dictionary by the numeric key.\r\n value = values[parseInt(value)]\r\n value = value.trim()\r\n if (value === '') {\r\n value = undefined\r\n }\r\n break\r\n\r\n case 'b':\r\n value = value === '1' ? true : false\r\n break\r\n\r\n // Stub: blank stub cell that is ignored by data processing utilities.\r\n case 'z':\r\n value = undefined\r\n break\r\n\r\n // Error: `value` is a numeric code.\r\n // They also wrote: \"and `w` property stores its common name\".\r\n // It's unclear what they meant by that.\r\n case 'e':\r\n value = decodeError(value)\r\n break\r\n\r\n // Date: a string to be parsed as a date.\r\n // (usually a string in \"ISO 8601\" format)\r\n case 'd':\r\n if (value === undefined) {\r\n break\r\n }\r\n value = new Date(value)\r\n break\r\n\r\n case 'n':\r\n if (value === undefined) {\r\n break\r\n }\r\n value = parseFloat(value)\r\n // XLSX does have \"d\" type for dates, but it's not commonly used.\r\n // Instead, spreadsheets prefer using \"n\" type for dates for some reason.\r\n //\r\n // In such cases, sometimes a \"date\" type could be heuristically detected\r\n // by looking at such numeric 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\n const styleId = getStyleId()\r\n if (styleId) {\r\n // styleId = parseInt(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 (BUILT_IN_DATE_NUMBER_FORMAT_IDS.indexOf(parseInt(style.numberFormat.id)) >= 0 ||\r\n (options.dateFormat && style.numberFormat.template === options.dateFormat) ||\r\n (options.smartDateParser !== false && style.numberFormat.template && isDateTemplate(style.numberFormat.template))) {\r\n value = parseDate(value, properties)\r\n }\r\n }\r\n break\r\n\r\n default:\r\n throw new TypeError(`Cell type not supported: ${type}`)\r\n }\r\n\r\n // Convert empty values to `null`.\r\n if (value === undefined) {\r\n value = null\r\n }\r\n\r\n return value\r\n}\r\n\r\n// Decodes numeric error code to a string code.\r\n// https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md\r\nfunction decodeError(errorCode) {\r\n // While the error values are determined by the application,\r\n // the following are some example error values that could be used:\r\n switch (errorCode) {\r\n case 0x00:\r\n return '#NULL!'\r\n case 0x07:\r\n return '#DIV/0!'\r\n case 0x0F:\r\n return '#VALUE!'\r\n case 0x17:\r\n return '#REF!'\r\n case 0x1D:\r\n return '#NAME?'\r\n case 0x24:\r\n return '#NUM!'\r\n case 0x2A:\r\n return '#N/A'\r\n case 0x2B:\r\n return '#GETTING_DATA'\r\n default:\r\n // Such error code doesn't exist. I made it up.\r\n return `#ERROR_${errorCode}`\r\n }\r\n}\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 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];"],"mappings":";;;;;;;AAAA;;;;;;;;;;AAEA;AACA,IAAMA,+BAA+B,GAAG,CAAC,EAAD,EAAI,EAAJ,EAAO,EAAP,EAAU,EAAV,EAAa,EAAb,EAAgB,EAAhB,EAAmB,EAAnB,EAAsB,EAAtB,EAAyB,EAAzB,EAA4B,E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;EAED,OAAOA,KAAP;AACD,C,CAED;AACA;;;AACA,SAASY,WAAT,CAAqBc,SAArB,EAAgC;EAC9B;EACA;EACA,QAAQA,SAAR;IACE,KAAK,IAAL;MACE,OAAO,QAAP;;IACF,KAAK,IAAL;MACE,OAAO,SAAP;;IACF,KAAK,IAAL;MACE,OAAO,SAAP;;IACF,KAAK,IAAL;MACE,OAAO,OAAP;;IACF,KAAK,IAAL;MACE,OAAO,QAAP;;IACF,KAAK,IAAL;MACE,OAAO,OAAP;;IACF,KAAK,IAAL;MACE,OAAO,MAAP;;IACF,KAAK,IAAL;MACE,OAAO,eAAP;;IACF;MACE;MACA,wBAAiBA,SAAjB;EAnBJ;AAqBD;;AAED,SAASH,cAAT,CAAwBF,QAAxB,EAAkC;EAChC;EACA;EACA;EACAA,QAAQ,GAAGA,QAAQ,CAACM,WAAT,EAAX;EACA,IAAMC,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,CAA7B"}
1
+ {"version":3,"file":"parseCellValue.js","names":["parseCellValue","value","type","getInlineStringValue","getInlineStringXml","getStyleId","styles","values","properties","options","parseString","undefined","Error","sharedStringIndex","Number","isNaN","length","decodeError","parsedDate","Date","parsedNumber","isDateTimestamp","parseDate","TypeError","errorCode","trim"],"sources":["../../source/read/parseCellValue.js"],"sourcesContent":["import parseDate from './parseDate.js'\r\nimport isDateTimestamp from './isDateTimestamp.js'\r\n\r\n// Parses a string `value` of a cell.\r\nexport default function parseCellValue(value, type, {\r\n getInlineStringValue,\r\n getInlineStringXml,\r\n getStyleId,\r\n styles,\r\n values,\r\n properties,\r\n options\r\n}) {\r\n if (!type) {\r\n // Default cell type is \"n\" (numeric).\r\n // http://www.datypic.com/sc/ooxml/t-ssml_CT_Cell.html\r\n type = 'n'\r\n }\r\n\r\n // Available Excel cell types:\r\n // https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md\r\n //\r\n // Some other document (seems to be old):\r\n // http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/ST_CellType.html\r\n //\r\n switch (type) {\r\n // XLSX tends to store all strings as \"shared\" (indexed) ones\r\n // using \"s\" cell type (for saving on strage space).\r\n // \"str\" cell type is then generally only used for storing\r\n // formula-pre-calculated cell values.\r\n case 'str':\r\n value = parseString(value, options)\r\n break\r\n\r\n // Sometimes, XLSX stores strings as \"inline\" strings rather than \"shared\" (indexed) ones.\r\n // Perhaps the specification doesn't force it to use one or another.\r\n // Example: `<sheetData><row r=\"1\"><c r=\"A1\" s=\"1\" t=\"inlineStr\"><is><t>Test 123</t></is></c></row></sheetData>`.\r\n case 'inlineStr':\r\n value = getInlineStringValue()\r\n if (value === undefined) {\r\n throw new Error(`Unsupported \"inline string\" cell value structure: ${getInlineStringXml()}`)\r\n }\r\n value = parseString(value, options)\r\n break\r\n\r\n // XLSX tends to store string values as \"shared\" (indexed) ones.\r\n // \"Shared\" strings is a way for an Excel editor to reduce\r\n // the file size by storing \"commonly used\" strings in a dictionary\r\n // and then referring to such strings by their index in that dictionary.\r\n // Example: `<sheetData><row r=\"1\"><c r=\"A1\" s=\"1\" t=\"s\"><v>0</v></c></row></sheetData>`.\r\n case 's':\r\n // If a cell has no value then there's no `<c/>` element for it.\r\n // If a `<c/>` element exists then it's not empty.\r\n // The `<v/>`alue is a key in the \"shared strings\" dictionary of the\r\n // XLSX file, so look it up in the `values` dictionary by the numeric key.\r\n const sharedStringIndex = Number(value)\r\n if (isNaN(sharedStringIndex)) {\r\n throw new Error(`Invalid \"shared\" string index: ${value}`)\r\n }\r\n if (sharedStringIndex >= values.length) {\r\n throw new Error(`An out-of-bounds \"shared\" string index: ${value}`)\r\n }\r\n value = values[sharedStringIndex]\r\n value = parseString(value, options)\r\n break\r\n\r\n // Boolean (TRUE/FALSE) values are stored as either \"1\" or \"0\"\r\n // in cells of type \"b\".\r\n case 'b':\r\n if (value === '1') {\r\n value = true\r\n } else if (value === '0') {\r\n value = false\r\n } else {\r\n throw new Error(`Unsupported \"boolean\" cell value: ${value}`)\r\n }\r\n break\r\n\r\n // XLSX specification seems to support cells of type \"z\":\r\n // blank \"stub\" cells that should be ignored by data processing utilities.\r\n case 'z':\r\n value = undefined\r\n break\r\n\r\n // XLSX specification also defines cells of type \"e\" containing a numeric \"error\" code.\r\n // It's not clear what that means though.\r\n // They also wrote: \"and `w` property stores its common name\".\r\n // It's unclear what they meant by that.\r\n case 'e':\r\n value = decodeError(value)\r\n break\r\n\r\n // XLSX supports date cells of type \"d\", though seems like it (almost?) never\r\n // uses it for storing dates, preferring \"n\" numeric timestamp cells instead.\r\n // The value of a \"d\" cell is supposedly a string in \"ISO 8601\" format.\r\n // I haven't seen an XLSX file having such cells.\r\n // Example: `<sheetData><row r=\"1\"><c r=\"A1\" s=\"1\" t=\"d\"><v>2021-06-10T00:47:45.700Z</v></c></row></sheetData>`.\r\n case 'd':\r\n if (value === undefined) {\r\n break\r\n }\r\n const parsedDate = new Date(value)\r\n if (isNaN(parsedDate)) {\r\n throw new Error(`Unsupported \"date\" cell value: ${value}`)\r\n }\r\n value = parsedDate\r\n break\r\n\r\n // Numeric cells have type \"n\".\r\n case 'n':\r\n if (value === undefined) {\r\n break\r\n }\r\n const parsedNumber = Number(value)\r\n if (isNaN(parsedNumber)) {\r\n throw new Error(`Invalid \"numeric\" cell value: ${value}`)\r\n }\r\n value = parsedNumber\r\n // 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 if (isDateTimestamp(value, getStyleId(), styles, options)) {\r\n // Parse the number as a date timestamp.\r\n value = parseDate(value, properties)\r\n }\r\n break\r\n\r\n default:\r\n throw new TypeError(`Cell type not supported: ${type}`)\r\n }\r\n\r\n // Convert empty values to `null`.\r\n if (value === undefined) {\r\n value = null\r\n }\r\n\r\n return value\r\n}\r\n\r\n// Decodes numeric error code to a string code.\r\n// https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md\r\nfunction decodeError(errorCode) {\r\n // While the error values are determined by the application,\r\n // the following are some example error values that could be used:\r\n switch (errorCode) {\r\n case 0x00:\r\n return '#NULL!'\r\n case 0x07:\r\n return '#DIV/0!'\r\n case 0x0F:\r\n return '#VALUE!'\r\n case 0x17:\r\n return '#REF!'\r\n case 0x1D:\r\n return '#NAME?'\r\n case 0x24:\r\n return '#NUM!'\r\n case 0x2A:\r\n return '#N/A'\r\n case 0x2B:\r\n return '#GETTING_DATA'\r\n default:\r\n // Such error code doesn't exist. I made it up.\r\n return `#ERROR_${errorCode}`\r\n }\r\n}\r\n\r\nfunction parseString(value, options) {\r\n // In some weird cases, a developer might want to disable\r\n // the automatic trimming of all strings.\r\n // For example, leading spaces might express a tree-like hierarchy.\r\n // https://github.com/catamphetamine/read-excel-file/pull/106#issuecomment-1136062917\r\n if (options.trim !== false) {\r\n value = value.trim()\r\n }\r\n if (value === '') {\r\n value = undefined\r\n }\r\n return value\r\n}"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA;AACe,SAASA,cAAT,CAAwBC,KAAxB,EAA+BC,IAA/B,QAQZ;EAAA,IAPDC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gC;EAC9B;EACA;EACA,QAAQA,SAAR;IACE,KAAK,IAAL;MACE,OAAO,QAAP;;IACF,KAAK,IAAL;MACE,OAAO,SAAP;;IACF,KAAK,IAAL;MACE,OAAO,SAAP;;IACF,KAAK,IAAL;MACE,OAAO,OAAP;;IACF,KAAK,IAAL;MACE,OAAO,QAAP;;IACF,KAAK,IAAL;MACE,OAAO,OAAP;;IACF,KAAK,IAAL;MACE,OAAO,MAAP;;IACF,KAAK,IAAL;MACE,OAAO,eAAP;;IACF;MACE;MACA,wBAAiBA,SAAjB;EAnBJ;AAqBD;;AAED,SAASd,WAAT,CAAqBT,KAArB,EAA4BQ,OAA5B,EAAqC;EACnC;EACA;EACA;EACA;EACA,IAAIA,OAAO,CAACgB,IAAR,KAAiB,KAArB,EAA4B;IAC1BxB,KAAK,GAAGA,KAAK,CAACwB,IAAN,EAAR;EACD;;EACD,IAAIxB,KAAK,KAAK,EAAd,EAAkB;IAChBA,KAAK,GAAGU,SAAR;EACD;;EACD,OAAOV,KAAP;AACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"parseDate.js","names":["parseExcelDate","excelSerialDate","options","epoch1904","daysBeforeUnixEpoch","hour","Date","Math","round"],"sources":["../../source/read/parseDate.js"],"sourcesContent":[" // Parses an Excel Date (\"serial\") into a corresponding javascript Date in UTC+0 timezone.\r\n // (with time equal to 00:00)\r\n //\r\n // https://www.pcworld.com/article/3063622/software/mastering-excel-date-time-serial-numbers-networkdays-datevalue-and-more.html\r\n // \"If you need to calculate dates in your spreadsheets,\r\n // Excel uses its own unique system, which it calls Serial Numbers\".\r\n //\r\n export default function parseExcelDate(excelSerialDate, options) {\r\n // https://support.microsoft.com/en-gb/help/214330/differences-between-the-1900-and-the-1904-date-system-in-excel\r\n if (options && options.epoch1904) {\r\n excelSerialDate += 1462\r\n }\r\n\r\n // \"Excel serial date\" is just\r\n // the count of days since `01/01/1900`\r\n // (seems that it may be even fractional).\r\n //\r\n // The count of days elapsed\r\n // since `01/01/1900` (Excel epoch)\r\n // till `01/01/1970` (Unix epoch).\r\n // Accounts for leap years\r\n // (19 of them, yielding 19 extra days).\r\n const daysBeforeUnixEpoch = 70 * 365 + 19\r\n\r\n // An hour, approximately, because a minute\r\n // may be longer than 60 seconds, due to \"leap seconds\".\r\n //\r\n // Still, Javascript `Date` (and UNIX time in general) intentionally\r\n // drops the concept of \"leap seconds\" in order to make things simpler.\r\n // So it's fine.\r\n // https://stackoverflow.com/questions/53019726/where-are-the-leap-seconds-in-javascript\r\n //\r\n // \"The JavaScript Date object specifically adheres to the concept of Unix Time\r\n // (albeit with higher precision). This is part of the POSIX specification,\r\n // and thus is sometimes called \"POSIX Time\". It does not count leap seconds,\r\n // but rather assumes every day had exactly 86,400 seconds. You can read about\r\n // this in section 20.3.1.1 of the current ECMAScript specification, which states:\r\n //\r\n // \"Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC.\r\n // In time values leap seconds are ignored. It is assumed that there are exactly\r\n // 86,400,000 milliseconds per day.\"\r\n //\r\n // The fact is, that the unpredictable nature of leap seconds makes them very\r\n // difficult to work with in APIs. One can't generally pass timestamps around\r\n // that need leap seconds tables to be interpreted correctly, and expect that\r\n // one system will interpret them the same as another. For example, while your\r\n // example timestamp 1483228826 is 2017-01-01T00:00:00Z on your system,\r\n // it would be interpreted as 2017-01-01T00:00:26Z on POSIX based systems,\r\n // or systems without leap second tables. So they aren't portable.\r\n // Even on systems that have full updated tables, there's no telling what those\r\n // tables will contain in the future (beyond the 6-month IERS announcement period),\r\n // so I can't produce a future timestamp without risk that it may eventually change.\r\n //\r\n // To be clear - to support leap seconds in a programming language, the implementation\r\n // must go out of its way to do so, and must make tradeoffs that are not always acceptable.\r\n // Though there are exceptions, the general position is to not support them - not because\r\n // of any subversion or active countermeasures, but because supporting them properly is much,\r\n // much harder.\"\r\n //\r\n // https://en.wikipedia.org/wiki/Unix_time#Leap_seconds\r\n // https://en.wikipedia.org/wiki/Leap_year\r\n // https://en.wikipedia.org/wiki/Leap_second\r\n //\r\n const hour = 60 * 60 * 1000\r\n\r\n return new Date(Math.round((excelSerialDate - daysBeforeUnixEpoch) * 24 * hour))\r\n }"],"mappings":";;;;;;;AAAI;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAwBC,eAAxB,EAAyCC,OAAzC,EAAkD;EAC/D;EACA,IAAIA,OAAO,IAAIA,OAAO,CAACC,SAAvB,EAAkC;IAChCF,eAAe,IAAI,IAAnB;EACD,CAJ8D,CAM/D;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;EACA,IAAMG,mBAAmB,GAAG,KAAK,GAAL,GAAW,EAAvC,CAf+D,CAiB/D;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EACA,IAAMC,IAAI,GAAG,KAAK,EAAL,GAAU,IAAvB;EAEA,OAAO,IAAIC,IAAJ,CAASC,IAAI,CAACC,KAAL,CAAW,CAACP,eAAe,GAAGG,mBAAnB,IAA0C,EAA1C,GAA+CC,IAA1D,CAAT,CAAP;AACD"}
1
+ {"version":3,"file":"parseDate.js","names":["parseExcelDate","excelSerialDate","options","epoch1904","daysBeforeUnixEpoch","hour","Date","Math","round"],"sources":["../../source/read/parseDate.js"],"sourcesContent":["// Parses an Excel Date (\"serial\") into a corresponding javascript Date in UTC+0 timezone.\r\n// (with time equal to 00:00)\r\n//\r\n// https://www.pcworld.com/article/3063622/software/mastering-excel-date-time-serial-numbers-networkdays-datevalue-and-more.html\r\n// \"If you need to calculate dates in your spreadsheets,\r\n// Excel uses its own unique system, which it calls Serial Numbers\".\r\n//\r\nexport default function parseExcelDate(excelSerialDate, options) {\r\n // https://support.microsoft.com/en-gb/help/214330/differences-between-the-1900-and-the-1904-date-system-in-excel\r\n if (options && options.epoch1904) {\r\n excelSerialDate += 1462\r\n }\r\n\r\n // \"Excel serial date\" is just\r\n // the count of days since `01/01/1900`\r\n // (seems that it may be even fractional).\r\n //\r\n // The count of days elapsed\r\n // since `01/01/1900` (Excel epoch)\r\n // till `01/01/1970` (Unix epoch).\r\n // Accounts for leap years\r\n // (19 of them, yielding 19 extra days).\r\n const daysBeforeUnixEpoch = 70 * 365 + 19\r\n\r\n // An hour, approximately, because a minute\r\n // may be longer than 60 seconds, due to \"leap seconds\".\r\n //\r\n // Still, Javascript `Date` (and UNIX time in general) intentionally\r\n // drops the concept of \"leap seconds\" in order to make things simpler.\r\n // So it's fine.\r\n // https://stackoverflow.com/questions/53019726/where-are-the-leap-seconds-in-javascript\r\n //\r\n // \"The JavaScript Date object specifically adheres to the concept of Unix Time\r\n // (albeit with higher precision). This is part of the POSIX specification,\r\n // and thus is sometimes called \"POSIX Time\". It does not count leap seconds,\r\n // but rather assumes every day had exactly 86,400 seconds. You can read about\r\n // this in section 20.3.1.1 of the current ECMAScript specification, which states:\r\n //\r\n // \"Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC.\r\n // In time values leap seconds are ignored. It is assumed that there are exactly\r\n // 86,400,000 milliseconds per day.\"\r\n //\r\n // The fact is, that the unpredictable nature of leap seconds makes them very\r\n // difficult to work with in APIs. One can't generally pass timestamps around\r\n // that need leap seconds tables to be interpreted correctly, and expect that\r\n // one system will interpret them the same as another. For example, while your\r\n // example timestamp 1483228826 is 2017-01-01T00:00:00Z on your system,\r\n // it would be interpreted as 2017-01-01T00:00:26Z on POSIX based systems,\r\n // or systems without leap second tables. So they aren't portable.\r\n // Even on systems that have full updated tables, there's no telling what those\r\n // tables will contain in the future (beyond the 6-month IERS announcement period),\r\n // so I can't produce a future timestamp without risk that it may eventually change.\r\n //\r\n // To be clear - to support leap seconds in a programming language, the implementation\r\n // must go out of its way to do so, and must make tradeoffs that are not always acceptable.\r\n // Though there are exceptions, the general position is to not support them - not because\r\n // of any subversion or active countermeasures, but because supporting them properly is much,\r\n // much harder.\"\r\n //\r\n // https://en.wikipedia.org/wiki/Unix_time#Leap_seconds\r\n // https://en.wikipedia.org/wiki/Leap_year\r\n // https://en.wikipedia.org/wiki/Leap_second\r\n //\r\n const hour = 60 * 60 * 1000\r\n\r\n return new Date(Math.round((excelSerialDate - daysBeforeUnixEpoch) * 24 * hour))\r\n}"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAwBC,eAAxB,EAAyCC,OAAzC,EAAkD;EAC/D;EACA,IAAIA,OAAO,IAAIA,OAAO,CAACC,SAAvB,EAAkC;IAChCF,eAAe,IAAI,IAAnB;EACD,CAJ8D,CAM/D;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;EACA,IAAMG,mBAAmB,GAAG,KAAK,GAAL,GAAW,EAAvC,CAf+D,CAiB/D;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;EACA,IAAMC,IAAI,GAAG,KAAK,EAAL,GAAU,IAAvB;EAEA,OAAO,IAAIC,IAAJ,CAASC,IAAI,CAACC,KAAL,CAAW,CAACP,eAAe,GAAGG,mBAAnB,IAA0C,EAA1C,GAA+CC,IAA1D,CAAT,CAAP;AACD"}