read-excel-file 9.1.1 → 9.3.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.
Files changed (206) hide show
  1. package/.gitlab-ci.yml +1 -1
  2. package/CHANGELOG.md +14 -0
  3. package/README.md +153 -50
  4. package/bundle/read-excel-file.min.js +1 -1
  5. package/bundle/read-excel-file.min.js.map +1 -1
  6. package/bundle/read-excel-file.min.old.js +2 -0
  7. package/bundle/read-excel-file.min.old.js.map +1 -0
  8. package/commonjs/export/convertValuesFromUint8ArraysToStrings.js +3 -0
  9. package/commonjs/export/convertValuesFromUint8ArraysToStrings.js.map +1 -1
  10. package/commonjs/export/parseSheet.js +12 -9
  11. package/commonjs/export/parseSheet.js.map +1 -1
  12. package/commonjs/export/readSheetBrowser.js +6 -2
  13. package/commonjs/export/readSheetBrowser.js.map +1 -1
  14. package/commonjs/export/readSheetNode.js +6 -2
  15. package/commonjs/export/readSheetNode.js.map +1 -1
  16. package/commonjs/export/readSheetUniversal.js +14 -2
  17. package/commonjs/export/readSheetUniversal.js.map +1 -1
  18. package/commonjs/export/readSheetWebWorker.js +12 -2
  19. package/commonjs/export/readSheetWebWorker.js.map +1 -1
  20. package/commonjs/export/readXlsxFileBrowser.js +6 -2
  21. package/commonjs/export/readXlsxFileBrowser.js.map +1 -1
  22. package/commonjs/export/readXlsxFileNode.js +6 -2
  23. package/commonjs/export/readXlsxFileNode.js.map +1 -1
  24. package/commonjs/export/readXlsxFileUniversal.js +14 -2
  25. package/commonjs/export/readXlsxFileUniversal.js.map +1 -1
  26. package/commonjs/export/readXlsxFileWebWorker.js +12 -2
  27. package/commonjs/export/readXlsxFileWebWorker.js.map +1 -1
  28. package/commonjs/export/unpackXlsxFileBrowser.js +29 -6
  29. package/commonjs/export/unpackXlsxFileBrowser.js.map +1 -1
  30. package/commonjs/export/unpackXlsxFileNode.js +6 -0
  31. package/commonjs/export/unpackXlsxFileNode.js.map +1 -1
  32. package/commonjs/export/unpackXlsxFileUniversal.js +6 -0
  33. package/commonjs/export/unpackXlsxFileUniversal.js.map +1 -1
  34. package/commonjs/export/unpackXlsxFileWebWorker.js +14 -0
  35. package/commonjs/export/unpackXlsxFileWebWorker.js.map +1 -0
  36. package/commonjs/parseSheetData/parseSheetData.js +6 -6
  37. package/commonjs/parseSheetData/parseSheetData.js.map +1 -1
  38. package/commonjs/utility/checkpoint.js +33 -0
  39. package/commonjs/utility/checkpoint.js.map +1 -0
  40. package/commonjs/utility/isObject.js +15 -0
  41. package/commonjs/utility/isObject.js.map +1 -0
  42. package/commonjs/utility/isPromise.js +18 -0
  43. package/commonjs/utility/isPromise.js.map +1 -0
  44. package/commonjs/xlsx/convertCellsToData2dArray.js +0 -3
  45. package/commonjs/xlsx/convertCellsToData2dArray.js.map +1 -1
  46. package/commonjs/xlsx/isDateFormatStyle.js +2 -2
  47. package/commonjs/xlsx/isDateFormatStyle.js.map +1 -1
  48. package/commonjs/xlsx/parseCell.js +89 -24
  49. package/commonjs/xlsx/parseCell.js.map +1 -1
  50. package/{modules/xlsx/parseCellCoordinates.js → commonjs/xlsx/parseCellAddress.js} +18 -7
  51. package/commonjs/xlsx/parseCellAddress.js.map +1 -0
  52. package/commonjs/xlsx/parseCellValue.js +7 -23
  53. package/commonjs/xlsx/parseCellValue.js.map +1 -1
  54. package/commonjs/xlsx/parseFilePaths.js +31 -32
  55. package/commonjs/xlsx/parseFilePaths.js.map +1 -1
  56. package/commonjs/xlsx/parseNumber.js +20 -0
  57. package/commonjs/xlsx/parseNumber.js.map +1 -0
  58. package/commonjs/xlsx/parseSharedString.js +64 -0
  59. package/commonjs/xlsx/parseSharedString.js.map +1 -0
  60. package/commonjs/xlsx/parseSharedStrings.js +45 -5
  61. package/commonjs/xlsx/parseSharedStrings.js.map +1 -1
  62. package/commonjs/xlsx/parseSheet.js +93 -9
  63. package/commonjs/xlsx/parseSheet.js.map +1 -1
  64. package/commonjs/xlsx/parseSheetData.js +68 -0
  65. package/commonjs/xlsx/parseSheetData.js.map +1 -0
  66. package/commonjs/xlsx/parseSpreadsheetContents.js +244 -43
  67. package/commonjs/xlsx/parseSpreadsheetContents.js.map +1 -1
  68. package/commonjs/xlsx/parseSpreadsheetInfo.js +67 -36
  69. package/commonjs/xlsx/parseSpreadsheetInfo.js.map +1 -1
  70. package/commonjs/xlsx/parseStyles.js +89 -36
  71. package/commonjs/xlsx/parseStyles.js.map +1 -1
  72. package/commonjs/xml/dom.js +2 -1
  73. package/commonjs/xml/dom.js.map +1 -1
  74. package/commonjs/xml/parseXmlStream.js +14 -0
  75. package/commonjs/xml/parseXmlStream.js.map +1 -0
  76. package/commonjs/xml/parseXmlStream.sax.js +109 -0
  77. package/commonjs/xml/parseXmlStream.sax.js.map +1 -0
  78. package/commonjs/xml/parseXmlStream.saxen.code.js +953 -0
  79. package/commonjs/xml/parseXmlStream.saxen.code.js.map +1 -0
  80. package/commonjs/xml/parseXmlStream.saxen.js +85 -0
  81. package/commonjs/xml/parseXmlStream.saxen.js.map +1 -0
  82. package/commonjs/xml/xlsx.js +75 -40
  83. package/commonjs/xml/xlsx.js.map +1 -1
  84. package/commonjs/zip/unzipFromArrayBuffer.js +5 -14
  85. package/commonjs/zip/unzipFromArrayBuffer.js.map +1 -1
  86. package/commonjs/zip/unzipFromStream.fflate.js +338 -0
  87. package/commonjs/zip/unzipFromStream.fflate.js.map +1 -0
  88. package/commonjs/zip/unzipFromStream.js +8 -200
  89. package/commonjs/zip/unzipFromStream.js.map +1 -1
  90. package/commonjs/zip/unzipFromStream.unzipper.js +138 -0
  91. package/commonjs/zip/unzipFromStream.unzipper.js.map +1 -0
  92. package/modules/export/convertValuesFromUint8ArraysToStrings.js +2 -0
  93. package/modules/export/convertValuesFromUint8ArraysToStrings.js.map +1 -1
  94. package/modules/export/parseSheet.js +12 -9
  95. package/modules/export/parseSheet.js.map +1 -1
  96. package/modules/export/readSheetBrowser.js +5 -2
  97. package/modules/export/readSheetBrowser.js.map +1 -1
  98. package/modules/export/readSheetNode.js +5 -2
  99. package/modules/export/readSheetNode.js.map +1 -1
  100. package/modules/export/readSheetUniversal.js +14 -2
  101. package/modules/export/readSheetUniversal.js.map +1 -1
  102. package/modules/export/readSheetWebWorker.js +12 -2
  103. package/modules/export/readSheetWebWorker.js.map +1 -1
  104. package/modules/export/readXlsxFileBrowser.js +5 -2
  105. package/modules/export/readXlsxFileBrowser.js.map +1 -1
  106. package/modules/export/readXlsxFileNode.js +5 -2
  107. package/modules/export/readXlsxFileNode.js.map +1 -1
  108. package/modules/export/readXlsxFileUniversal.js +14 -2
  109. package/modules/export/readXlsxFileUniversal.js.map +1 -1
  110. package/modules/export/readXlsxFileWebWorker.js +12 -2
  111. package/modules/export/readXlsxFileWebWorker.js.map +1 -1
  112. package/modules/export/unpackXlsxFileBrowser.js +26 -6
  113. package/modules/export/unpackXlsxFileBrowser.js.map +1 -1
  114. package/modules/export/unpackXlsxFileNode.js +3 -0
  115. package/modules/export/unpackXlsxFileNode.js.map +1 -1
  116. package/modules/export/unpackXlsxFileUniversal.js +3 -0
  117. package/modules/export/unpackXlsxFileUniversal.js.map +1 -1
  118. package/modules/export/unpackXlsxFileWebWorker.js +6 -0
  119. package/modules/export/unpackXlsxFileWebWorker.js.map +1 -0
  120. package/modules/parseSheetData/parseSheetData.js +4 -4
  121. package/modules/parseSheetData/parseSheetData.js.map +1 -1
  122. package/modules/utility/checkpoint.js +25 -0
  123. package/modules/utility/checkpoint.js.map +1 -0
  124. package/modules/utility/isObject.js +9 -0
  125. package/modules/utility/isObject.js.map +1 -0
  126. package/modules/utility/isPromise.js +12 -0
  127. package/modules/utility/isPromise.js.map +1 -0
  128. package/modules/xlsx/convertCellsToData2dArray.js +0 -3
  129. package/modules/xlsx/convertCellsToData2dArray.js.map +1 -1
  130. package/modules/xlsx/isDateFormatStyle.js +2 -2
  131. package/modules/xlsx/isDateFormatStyle.js.map +1 -1
  132. package/modules/xlsx/parseCell.js +85 -24
  133. package/modules/xlsx/parseCell.js.map +1 -1
  134. package/{commonjs/xlsx/parseCellCoordinates.js → modules/xlsx/parseCellAddress.js} +12 -13
  135. package/modules/xlsx/parseCellAddress.js.map +1 -0
  136. package/modules/xlsx/parseCellValue.js +7 -23
  137. package/modules/xlsx/parseCellValue.js.map +1 -1
  138. package/modules/xlsx/parseFilePaths.js +31 -33
  139. package/modules/xlsx/parseFilePaths.js.map +1 -1
  140. package/modules/xlsx/parseNumber.js +14 -0
  141. package/modules/xlsx/parseNumber.js.map +1 -0
  142. package/modules/xlsx/parseSharedString.js +55 -0
  143. package/modules/xlsx/parseSharedString.js.map +1 -0
  144. package/modules/xlsx/parseSharedStrings.js +46 -5
  145. package/modules/xlsx/parseSharedStrings.js.map +1 -1
  146. package/modules/xlsx/parseSheet.js +91 -9
  147. package/modules/xlsx/parseSheet.js.map +1 -1
  148. package/modules/xlsx/parseSheetData.js +55 -0
  149. package/modules/xlsx/parseSheetData.js.map +1 -0
  150. package/modules/xlsx/parseSpreadsheetContents.js +242 -43
  151. package/modules/xlsx/parseSpreadsheetContents.js.map +1 -1
  152. package/modules/xlsx/parseSpreadsheetInfo.js +67 -37
  153. package/modules/xlsx/parseSpreadsheetInfo.js.map +1 -1
  154. package/modules/xlsx/parseStyles.js +88 -36
  155. package/modules/xlsx/parseStyles.js.map +1 -1
  156. package/modules/xml/dom.js +2 -1
  157. package/modules/xml/dom.js.map +1 -1
  158. package/modules/xml/parseXmlStream.js +18 -0
  159. package/modules/xml/parseXmlStream.js.map +1 -0
  160. package/modules/xml/parseXmlStream.sax.js +103 -0
  161. package/modules/xml/parseXmlStream.sax.js.map +1 -0
  162. package/modules/xml/parseXmlStream.saxen.code.js +947 -0
  163. package/modules/xml/parseXmlStream.saxen.code.js.map +1 -0
  164. package/modules/xml/parseXmlStream.saxen.js +79 -0
  165. package/modules/xml/parseXmlStream.saxen.js.map +1 -0
  166. package/modules/xml/xlsx.js +72 -36
  167. package/modules/xml/xlsx.js.map +1 -1
  168. package/modules/zip/unzipFromArrayBuffer.js +5 -14
  169. package/modules/zip/unzipFromArrayBuffer.js.map +1 -1
  170. package/modules/zip/unzipFromStream.fflate.js +336 -0
  171. package/modules/zip/unzipFromStream.fflate.js.map +1 -0
  172. package/modules/zip/unzipFromStream.js +55 -187
  173. package/modules/zip/unzipFromStream.js.map +1 -1
  174. package/modules/zip/unzipFromStream.unzipper.js +133 -0
  175. package/modules/zip/unzipFromStream.unzipper.js.map +1 -0
  176. package/package.json +12 -32
  177. package/commonjs/xlsx/parseCellCoordinates.js.map +0 -1
  178. package/commonjs/xlsx/parseCells.js +0 -34
  179. package/commonjs/xlsx/parseCells.js.map +0 -1
  180. package/commonjs/xlsx/parseSheetDimensions.js +0 -43
  181. package/commonjs/xlsx/parseSheetDimensions.js.map +0 -1
  182. package/commonjs/xml/xml.js +0 -13
  183. package/commonjs/xml/xml.js.map +0 -1
  184. package/commonjs/xml/xmlBrowser.js +0 -17
  185. package/commonjs/xml/xmlBrowser.js.map +0 -1
  186. package/commonjs/xml/xpath/xlsx-xpath.js +0 -92
  187. package/commonjs/xml/xpath/xlsx-xpath.js.map +0 -1
  188. package/commonjs/xml/xpath/xpathBrowser.js +0 -33
  189. package/commonjs/xml/xpath/xpathBrowser.js.map +0 -1
  190. package/commonjs/xml/xpath/xpathNode.js +0 -16
  191. package/commonjs/xml/xpath/xpathNode.js.map +0 -1
  192. package/modules/xlsx/parseCellCoordinates.js.map +0 -1
  193. package/modules/xlsx/parseCells.js +0 -27
  194. package/modules/xlsx/parseCells.js.map +0 -1
  195. package/modules/xlsx/parseSheetDimensions.js +0 -37
  196. package/modules/xlsx/parseSheetDimensions.js.map +0 -1
  197. package/modules/xml/xml.js +0 -7
  198. package/modules/xml/xml.js.map +0 -1
  199. package/modules/xml/xmlBrowser.js +0 -11
  200. package/modules/xml/xmlBrowser.js.map +0 -1
  201. package/modules/xml/xpath/xlsx-xpath.js +0 -73
  202. package/modules/xml/xpath/xlsx-xpath.js.map +0 -1
  203. package/modules/xml/xpath/xpathBrowser.js +0 -27
  204. package/modules/xml/xpath/xpathBrowser.js.map +0 -1
  205. package/modules/xml/xpath/xpathNode.js +0 -9
  206. package/modules/xml/xpath/xpathNode.js.map +0 -1
@@ -1,8 +1,49 @@
1
- import { getSharedStrings } from '../xml/xlsx.js';
2
- export default function parseSharedStrings(content, xml) {
3
- if (!content) {
4
- return [];
1
+ import { onOpenTagInSharedString, onCloseTagInSharedString, onTextInSharedString, createInitialStateInSharedString } from './parseSharedString.js';
2
+
3
+ /**
4
+ * Parses `sharedStrings.xml` file.
5
+ * @param {string} content
6
+ * @param {function} parseXmlStream — SAX XML parser.
7
+ * @returns {Promise<string[]>}
8
+ */
9
+ export default function parseSharedStrings(content, parseXmlStream) {
10
+ return parseXmlStream(content, {
11
+ createInitialState: createInitialStateInSharedStrings,
12
+ onOpenTag: onOpenTagInSharedStrings,
13
+ onCloseTag: onCloseTagInSharedStrings,
14
+ onText: onTextInSharedStrings
15
+ }).then(function (state) {
16
+ return state.strings;
17
+ });
18
+ }
19
+ function createInitialStateInSharedStrings() {
20
+ return {
21
+ si: undefined,
22
+ strings: []
23
+ };
24
+ }
25
+
26
+ // In an XLSX `sharedStrings.xml` file, a <si/> (string item) element can have
27
+ // either a single child <t/> element (meaning that "rich formatting" is not used)
28
+ // or multiple child <r/> elements (meaning that "rich formatting" is used).
29
+ function onOpenTagInSharedStrings(tagName, attributes, state) {
30
+ if (tagName === 'si') {
31
+ state.si = createInitialStateInSharedString();
32
+ } else if (state.si) {
33
+ onOpenTagInSharedString(tagName, attributes, state.si);
34
+ }
35
+ }
36
+ function onCloseTagInSharedStrings(tagName, state) {
37
+ if (tagName === 'si') {
38
+ state.strings.push(state.si.string);
39
+ state.si = undefined;
40
+ } else if (state.si) {
41
+ onCloseTagInSharedString(tagName, state.si);
42
+ }
43
+ }
44
+ function onTextInSharedStrings(text, state) {
45
+ if (state.si) {
46
+ onTextInSharedString(text, state.si);
5
47
  }
6
- return getSharedStrings(xml.createDocument(content));
7
48
  }
8
49
  //# sourceMappingURL=parseSharedStrings.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseSharedStrings.js","names":["getSharedStrings","parseSharedStrings","content","xml","createDocument"],"sources":["../../source/xlsx/parseSharedStrings.js"],"sourcesContent":["import {\r\n getSharedStrings\r\n} from '../xml/xlsx.js'\r\n\r\nexport default function parseSharedStrings(content, xml) {\r\n if (!content) {\r\n return []\r\n }\r\n return getSharedStrings(xml.createDocument(content))\r\n}"],"mappings":"AAAA,SACEA,gBAAgB,QACX,gBAAgB;AAEvB,eAAe,SAASC,kBAAkBA,CAACC,OAAO,EAAEC,GAAG,EAAE;EACvD,IAAI,CAACD,OAAO,EAAE;IACZ,OAAO,EAAE;EACX;EACA,OAAOF,gBAAgB,CAACG,GAAG,CAACC,cAAc,CAACF,OAAO,CAAC,CAAC;AACtD"}
1
+ {"version":3,"file":"parseSharedStrings.js","names":["onOpenTagInSharedString","onCloseTagInSharedString","onTextInSharedString","createInitialStateInSharedString","parseSharedStrings","content","parseXmlStream","createInitialState","createInitialStateInSharedStrings","onOpenTag","onOpenTagInSharedStrings","onCloseTag","onCloseTagInSharedStrings","onText","onTextInSharedStrings","then","state","strings","si","undefined","tagName","attributes","push","string","text"],"sources":["../../source/xlsx/parseSharedStrings.js"],"sourcesContent":["import {\r\n onOpenTagInSharedString,\r\n onCloseTagInSharedString,\r\n onTextInSharedString,\r\n createInitialStateInSharedString\r\n} from './parseSharedString.js'\r\n\r\n/**\r\n * Parses `sharedStrings.xml` file.\r\n * @param {string} content\r\n * @param {function} parseXmlStream — SAX XML parser.\r\n * @returns {Promise<string[]>}\r\n */\r\nexport default function parseSharedStrings(content, parseXmlStream) {\r\n return parseXmlStream(content, {\r\n createInitialState: createInitialStateInSharedStrings,\r\n onOpenTag: onOpenTagInSharedStrings,\r\n onCloseTag: onCloseTagInSharedStrings,\r\n onText: onTextInSharedStrings\r\n }).then((state) => {\r\n return state.strings\r\n })\r\n}\r\n\r\nfunction createInitialStateInSharedStrings() {\r\n return {\r\n si: undefined,\r\n strings: []\r\n }\r\n}\r\n\r\n// In an XLSX `sharedStrings.xml` file, a <si/> (string item) element can have\r\n// either a single child <t/> element (meaning that \"rich formatting\" is not used)\r\n// or multiple child <r/> elements (meaning that \"rich formatting\" is used).\r\nfunction onOpenTagInSharedStrings(tagName, attributes, state) {\r\n if (tagName === 'si') {\r\n state.si = createInitialStateInSharedString()\r\n } else if (state.si) {\r\n onOpenTagInSharedString(tagName, attributes, state.si)\r\n }\r\n}\r\n\r\nfunction onCloseTagInSharedStrings(tagName, state) {\r\n if (tagName === 'si') {\r\n state.strings.push(state.si.string)\r\n state.si = undefined\r\n } else if (state.si) {\r\n onCloseTagInSharedString(tagName, state.si)\r\n }\r\n}\r\n\r\nfunction onTextInSharedStrings(text, state) {\r\n if (state.si) {\r\n onTextInSharedString(text, state.si)\r\n }\r\n}"],"mappings":"AAAA,SACEA,uBAAuB,EACvBC,wBAAwB,EACxBC,oBAAoB,EACpBC,gCAAgC,QAC3B,wBAAwB;;AAE/B;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,kBAAkBA,CAACC,OAAO,EAAEC,cAAc,EAAE;EAClE,OAAOA,cAAc,CAACD,OAAO,EAAE;IAC7BE,kBAAkB,EAAEC,iCAAiC;IACrDC,SAAS,EAAEC,wBAAwB;IACnCC,UAAU,EAAEC,yBAAyB;IACrCC,MAAM,EAAEC;EACV,CAAC,CAAC,CAACC,IAAI,CAAC,UAACC,KAAK,EAAK;IACjB,OAAOA,KAAK,CAACC,OAAO;EACtB,CAAC,CAAC;AACJ;AAEA,SAAST,iCAAiCA,CAAA,EAAG;EAC3C,OAAO;IACLU,EAAE,EAAEC,SAAS;IACbF,OAAO,EAAE;EACX,CAAC;AACH;;AAEA;AACA;AACA;AACA,SAASP,wBAAwBA,CAACU,OAAO,EAAEC,UAAU,EAAEL,KAAK,EAAE;EAC5D,IAAII,OAAO,KAAK,IAAI,EAAE;IACpBJ,KAAK,CAACE,EAAE,GAAGf,gCAAgC,CAAC,CAAC;EAC/C,CAAC,MAAM,IAAIa,KAAK,CAACE,EAAE,EAAE;IACnBlB,uBAAuB,CAACoB,OAAO,EAAEC,UAAU,EAAEL,KAAK,CAACE,EAAE,CAAC;EACxD;AACF;AAEA,SAASN,yBAAyBA,CAACQ,OAAO,EAAEJ,KAAK,EAAE;EACjD,IAAII,OAAO,KAAK,IAAI,EAAE;IACpBJ,KAAK,CAACC,OAAO,CAACK,IAAI,CAACN,KAAK,CAACE,EAAE,CAACK,MAAM,CAAC;IACnCP,KAAK,CAACE,EAAE,GAAGC,SAAS;EACtB,CAAC,MAAM,IAAIH,KAAK,CAACE,EAAE,EAAE;IACnBjB,wBAAwB,CAACmB,OAAO,EAAEJ,KAAK,CAACE,EAAE,CAAC;EAC7C;AACF;AAEA,SAASJ,qBAAqBA,CAACU,IAAI,EAAER,KAAK,EAAE;EAC1C,IAAIA,KAAK,CAACE,EAAE,EAAE;IACZhB,oBAAoB,CAACsB,IAAI,EAAER,KAAK,CAACE,EAAE,CAAC;EACtC;AACF"}
@@ -1,14 +1,96 @@
1
- import parseCells from './parseCells.js';
2
- import parseSheetDimensions from './parseSheetDimensions.js';
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ 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); }
4
+ 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; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import parseSheetData, { createInitialStateInSheetData, onOpenTagInSheetData, onCloseTagInSheetData, onTextInSheetData } from './parseSheetData.js';
8
+ import parseCellAddress from './parseCellAddress.js';
3
9
  import reconstructSheetDimensionsFromSheetCells from './reconstructSheetDimensionsFromSheetCells.js';
4
10
  import convertSheetToData2dArray from './convertCellsToData2dArray.js';
5
- export default function parseSheet(content, xml, sharedStrings, styles, epoch1904, options) {
6
- var sheetDocument = xml.createDocument(content);
7
- var cells = parseCells(sheetDocument, sharedStrings, styles, epoch1904, options);
8
11
 
9
- // `dimensions` defines the spreadsheet area enclosing all non-empty cells.
10
- // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1
11
- var dimensions = parseSheetDimensions(sheetDocument) || reconstructSheetDimensionsFromSheetCells(cells);
12
- return convertSheetToData2dArray(cells, dimensions);
12
+ /**
13
+ * Parses a `sheet.xml` file.
14
+ * @param {string} content
15
+ * @param {function} parseXmlStream — SAX XML parser.
16
+ * @param {object} options
17
+ * @returns {Promise<SheetData>}
18
+ */
19
+ export default function parseSheet(content, parseXmlStream, _ref) {
20
+ var sharedStrings = _ref.sharedStrings,
21
+ styles = _ref.styles,
22
+ epoch1904 = _ref.epoch1904,
23
+ options = _ref.options;
24
+ // When XML parser is finished, it returns a `state`
25
+ // where it has accumulated the cells it encountered during parsing.
26
+ // `getSheetData()` function reads the parser `state` and transforms it to `SheetData`.
27
+ var getSheetData = function getSheetData(state) {
28
+ var cells = parseSheetData(state.sheetData, sharedStrings, styles, epoch1904, options);
29
+ var dimensions = state.dimension ? parseSheetDimensionRef(state.dimension) : reconstructSheetDimensionsFromSheetCells(cells);
30
+ return convertSheetToData2dArray(cells, dimensions);
31
+ };
32
+ return parseXmlStream(content, {
33
+ createInitialState: createInitialStateInSheet,
34
+ onOpenTag: onOpenTagInSheet,
35
+ onCloseTag: onCloseTagInSheet,
36
+ onText: onTextInSheet
37
+ }).then(function (state) {
38
+ return getSheetData(state);
39
+ });
40
+ }
41
+ function createInitialStateInSheet() {
42
+ return {
43
+ dimension: undefined,
44
+ sheetData: undefined
45
+ };
46
+ }
47
+ function onOpenTagInSheet(tagName, attributes, state) {
48
+ if (tagName === 'dimension') {
49
+ state.dimension = attributes.ref;
50
+ } else if (tagName === 'sheetData') {
51
+ state.sheetData = createInitialStateInSheetData();
52
+ } else if (state.sheetData) {
53
+ onOpenTagInSheetData(tagName, attributes, state.sheetData);
54
+ }
55
+ }
56
+ function onCloseTagInSheet(tagName, state) {
57
+ if (state.sheetData) {
58
+ onCloseTagInSheetData(tagName, state.sheetData);
59
+ }
60
+ }
61
+ function onTextInSheet(text, state) {
62
+ if (state.sheetData) {
63
+ onTextInSheetData(text, state.sheetData);
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Sheet "dimension" defines the spreadsheet area containing all non-empty cells.
69
+ * Any cells outside the "dimension" are considered empty and should be ignored.
70
+ * https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1
71
+ * @param {string} `ref` — The value of `<dimension ref/>` attribute.
72
+ * @returns {object[]} `undefined` or `[{ row, column }, { row, column }]` — "From row number and column number to row number and column number".
73
+ */
74
+ function parseSheetDimensionRef(ref) {
75
+ var dimensions = ref.split(':').map(parseCellAddress).map(function (_ref2) {
76
+ var _ref3 = _slicedToArray(_ref2, 2),
77
+ row = _ref3[0],
78
+ column = _ref3[1];
79
+ return {
80
+ row: row,
81
+ column: column
82
+ };
83
+ });
84
+ // Sometimes there can be just a single cell as a spreadsheet's "dimensions".
85
+ // For example, the default "dimensions" in Apache POI library is "A1",
86
+ // meaning that only the first cell in the spreadsheet is used.
87
+ //
88
+ // A quote from Apache POI library:
89
+ // "Single cell ranges are formatted like single cell references (e.g. 'A1' instead of 'A1:A1')."
90
+ //
91
+ if (dimensions.length === 1) {
92
+ dimensions = [dimensions[0], dimensions[0]];
93
+ }
94
+ return dimensions;
13
95
  }
14
96
  //# sourceMappingURL=parseSheet.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseSheet.js","names":["parseCells","parseSheetDimensions","reconstructSheetDimensionsFromSheetCells","convertSheetToData2dArray","parseSheet","content","xml","sharedStrings","styles","epoch1904","options","sheetDocument","createDocument","cells","dimensions"],"sources":["../../source/xlsx/parseSheet.js"],"sourcesContent":["import parseCells from './parseCells.js'\r\nimport parseSheetDimensions from './parseSheetDimensions.js'\r\nimport reconstructSheetDimensionsFromSheetCells from './reconstructSheetDimensionsFromSheetCells.js'\r\nimport convertSheetToData2dArray from './convertCellsToData2dArray.js'\r\n\r\nexport default function parseSheet(content, xml, sharedStrings, styles, epoch1904, options) {\r\n const sheetDocument = xml.createDocument(content)\r\n\r\n const cells = parseCells(sheetDocument, sharedStrings, styles, epoch1904, options)\r\n\r\n // `dimensions` defines the spreadsheet area enclosing all non-empty cells.\r\n // https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1\r\n const dimensions = parseSheetDimensions(sheetDocument) || reconstructSheetDimensionsFromSheetCells(cells)\r\n\r\n return convertSheetToData2dArray(cells, dimensions)\r\n}"],"mappings":"AAAA,OAAOA,UAAU,MAAM,iBAAiB;AACxC,OAAOC,oBAAoB,MAAM,2BAA2B;AAC5D,OAAOC,wCAAwC,MAAM,+CAA+C;AACpG,OAAOC,yBAAyB,MAAM,gCAAgC;AAEtE,eAAe,SAASC,UAAUA,CAACC,OAAO,EAAEC,GAAG,EAAEC,aAAa,EAAEC,MAAM,EAAEC,SAAS,EAAEC,OAAO,EAAE;EAC1F,IAAMC,aAAa,GAAGL,GAAG,CAACM,cAAc,CAACP,OAAO,CAAC;EAEjD,IAAMQ,KAAK,GAAGb,UAAU,CAACW,aAAa,EAAEJ,aAAa,EAAEC,MAAM,EAAEC,SAAS,EAAEC,OAAO,CAAC;;EAElF;EACA;EACA,IAAMI,UAAU,GAAGb,oBAAoB,CAACU,aAAa,CAAC,IAAIT,wCAAwC,CAACW,KAAK,CAAC;EAEzG,OAAOV,yBAAyB,CAACU,KAAK,EAAEC,UAAU,CAAC;AACrD"}
1
+ {"version":3,"file":"parseSheet.js","names":["parseSheetData","createInitialStateInSheetData","onOpenTagInSheetData","onCloseTagInSheetData","onTextInSheetData","parseCellAddress","reconstructSheetDimensionsFromSheetCells","convertSheetToData2dArray","parseSheet","content","parseXmlStream","_ref","sharedStrings","styles","epoch1904","options","getSheetData","state","cells","sheetData","dimensions","dimension","parseSheetDimensionRef","createInitialState","createInitialStateInSheet","onOpenTag","onOpenTagInSheet","onCloseTag","onCloseTagInSheet","onText","onTextInSheet","then","undefined","tagName","attributes","ref","text","split","map","_ref2","_ref3","_slicedToArray","row","column","length"],"sources":["../../source/xlsx/parseSheet.js"],"sourcesContent":["import parseSheetData, {\r\n createInitialStateInSheetData,\r\n onOpenTagInSheetData,\r\n onCloseTagInSheetData,\r\n onTextInSheetData\r\n} from './parseSheetData.js'\r\n\r\nimport parseCellAddress from './parseCellAddress.js'\r\n\r\nimport reconstructSheetDimensionsFromSheetCells from './reconstructSheetDimensionsFromSheetCells.js'\r\nimport convertSheetToData2dArray from './convertCellsToData2dArray.js'\r\n\r\n/**\r\n * Parses a `sheet.xml` file.\r\n * @param {string} content\r\n * @param {function} parseXmlStream — SAX XML parser.\r\n * @param {object} options\r\n * @returns {Promise<SheetData>}\r\n */\r\nexport default function parseSheet(content, parseXmlStream, { sharedStrings, styles, epoch1904, options }) {\r\n // When XML parser is finished, it returns a `state`\r\n // where it has accumulated the cells it encountered during parsing.\r\n // `getSheetData()` function reads the parser `state` and transforms it to `SheetData`.\r\n const getSheetData = (state) => {\r\n const cells = parseSheetData(state.sheetData, sharedStrings, styles, epoch1904, options)\r\n const dimensions = state.dimension\r\n ? parseSheetDimensionRef(state.dimension)\r\n : reconstructSheetDimensionsFromSheetCells(cells)\r\n return convertSheetToData2dArray(cells, dimensions)\r\n }\r\n\r\n return parseXmlStream(content, {\r\n createInitialState: createInitialStateInSheet,\r\n onOpenTag: onOpenTagInSheet,\r\n onCloseTag: onCloseTagInSheet,\r\n onText: onTextInSheet\r\n }).then((state) => {\r\n return getSheetData(state)\r\n })\r\n}\r\n\r\nfunction createInitialStateInSheet() {\r\n return {\r\n dimension: undefined,\r\n sheetData: undefined\r\n }\r\n}\r\n\r\nfunction onOpenTagInSheet(tagName, attributes, state) {\r\n if (tagName === 'dimension') {\r\n state.dimension = attributes.ref\r\n } else if (tagName === 'sheetData') {\r\n state.sheetData = createInitialStateInSheetData()\r\n } else if (state.sheetData) {\r\n onOpenTagInSheetData(tagName, attributes, state.sheetData)\r\n }\r\n}\r\n\r\nfunction onCloseTagInSheet(tagName, state) {\r\n if (state.sheetData) {\r\n onCloseTagInSheetData(tagName, state.sheetData)\r\n }\r\n}\r\n\r\nfunction onTextInSheet(text, state) {\r\n if (state.sheetData) {\r\n onTextInSheetData(text, state.sheetData)\r\n }\r\n}\r\n\r\n/**\r\n * Sheet \"dimension\" defines the spreadsheet area containing all non-empty cells.\r\n * Any cells outside the \"dimension\" are considered empty and should be ignored.\r\n * https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1\r\n * @param {string} `ref` — The value of `<dimension ref/>` attribute.\r\n * @returns {object[]} `undefined` or `[{ row, column }, { row, column }]` — \"From row number and column number to row number and column number\".\r\n */\r\nfunction parseSheetDimensionRef(ref) {\r\n let dimensions = ref.split(':').map(parseCellAddress).map(\r\n ([row, column]) => ({ row, column })\r\n )\r\n // Sometimes there can be just a single cell as a spreadsheet's \"dimensions\".\r\n // For example, the default \"dimensions\" in Apache POI library is \"A1\",\r\n // meaning that only the first cell in the spreadsheet is used.\r\n //\r\n // A quote from Apache POI library:\r\n // \"Single cell ranges are formatted like single cell references (e.g. 'A1' instead of 'A1:A1').\"\r\n //\r\n if (dimensions.length === 1) {\r\n dimensions = [dimensions[0], dimensions[0]]\r\n }\r\n return dimensions\r\n}"],"mappings":";;;;;;AAAA,OAAOA,cAAc,IACnBC,6BAA6B,EAC7BC,oBAAoB,EACpBC,qBAAqB,EACrBC,iBAAiB,QACZ,qBAAqB;AAE5B,OAAOC,gBAAgB,MAAM,uBAAuB;AAEpD,OAAOC,wCAAwC,MAAM,+CAA+C;AACpG,OAAOC,yBAAyB,MAAM,gCAAgC;;AAEtE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,UAAUA,CAACC,OAAO,EAAEC,cAAc,EAAAC,IAAA,EAAiD;EAAA,IAA7CC,aAAa,GAAAD,IAAA,CAAbC,aAAa;IAAEC,MAAM,GAAAF,IAAA,CAANE,MAAM;IAAEC,SAAS,GAAAH,IAAA,CAATG,SAAS;IAAEC,OAAO,GAAAJ,IAAA,CAAPI,OAAO;EACrG;EACA;EACA;EACA,IAAMC,YAAY,GAAG,SAAfA,YAAYA,CAAIC,KAAK,EAAK;IAC9B,IAAMC,KAAK,GAAGlB,cAAc,CAACiB,KAAK,CAACE,SAAS,EAAEP,aAAa,EAAEC,MAAM,EAAEC,SAAS,EAAEC,OAAO,CAAC;IACxF,IAAMK,UAAU,GAAGH,KAAK,CAACI,SAAS,GAC9BC,sBAAsB,CAACL,KAAK,CAACI,SAAS,CAAC,GACvCf,wCAAwC,CAACY,KAAK,CAAC;IACnD,OAAOX,yBAAyB,CAACW,KAAK,EAAEE,UAAU,CAAC;EACrD,CAAC;EAED,OAAOV,cAAc,CAACD,OAAO,EAAE;IAC7Bc,kBAAkB,EAAEC,yBAAyB;IAC7CC,SAAS,EAAEC,gBAAgB;IAC3BC,UAAU,EAAEC,iBAAiB;IAC7BC,MAAM,EAAEC;EACV,CAAC,CAAC,CAACC,IAAI,CAAC,UAACd,KAAK,EAAK;IACjB,OAAOD,YAAY,CAACC,KAAK,CAAC;EAC5B,CAAC,CAAC;AACJ;AAEA,SAASO,yBAAyBA,CAAA,EAAG;EACnC,OAAO;IACLH,SAAS,EAAEW,SAAS;IACpBb,SAAS,EAAEa;EACb,CAAC;AACH;AAEA,SAASN,gBAAgBA,CAACO,OAAO,EAAEC,UAAU,EAAEjB,KAAK,EAAE;EACpD,IAAIgB,OAAO,KAAK,WAAW,EAAE;IAC3BhB,KAAK,CAACI,SAAS,GAAGa,UAAU,CAACC,GAAG;EAClC,CAAC,MAAM,IAAIF,OAAO,KAAK,WAAW,EAAE;IAClChB,KAAK,CAACE,SAAS,GAAGlB,6BAA6B,CAAC,CAAC;EACnD,CAAC,MAAM,IAAIgB,KAAK,CAACE,SAAS,EAAE;IAC1BjB,oBAAoB,CAAC+B,OAAO,EAAEC,UAAU,EAAEjB,KAAK,CAACE,SAAS,CAAC;EAC5D;AACF;AAEA,SAASS,iBAAiBA,CAACK,OAAO,EAAEhB,KAAK,EAAE;EACzC,IAAIA,KAAK,CAACE,SAAS,EAAE;IACnBhB,qBAAqB,CAAC8B,OAAO,EAAEhB,KAAK,CAACE,SAAS,CAAC;EACjD;AACF;AAEA,SAASW,aAAaA,CAACM,IAAI,EAAEnB,KAAK,EAAE;EAClC,IAAIA,KAAK,CAACE,SAAS,EAAE;IACnBf,iBAAiB,CAACgC,IAAI,EAAEnB,KAAK,CAACE,SAAS,CAAC;EAC1C;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASG,sBAAsBA,CAACa,GAAG,EAAE;EACnC,IAAIf,UAAU,GAAGe,GAAG,CAACE,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAACjC,gBAAgB,CAAC,CAACiC,GAAG,CACvD,UAAAC,KAAA;IAAA,IAAAC,KAAA,GAAAC,cAAA,CAAAF,KAAA;MAAEG,GAAG,GAAAF,KAAA;MAAEG,MAAM,GAAAH,KAAA;IAAA,OAAO;MAAEE,GAAG,EAAHA,GAAG;MAAEC,MAAM,EAANA;IAAO,CAAC;EAAA,CACrC,CAAC;EACD;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAIvB,UAAU,CAACwB,MAAM,KAAK,CAAC,EAAE;IAC3BxB,UAAU,GAAG,CAACA,UAAU,CAAC,CAAC,CAAC,EAAEA,UAAU,CAAC,CAAC,CAAC,CAAC;EAC7C;EACA,OAAOA,UAAU;AACnB"}
@@ -0,0 +1,55 @@
1
+ import parseCell, { createInitialStateInCell, onOpenTagInCell, onCloseTagInCell, onTextInCell } from './parseCell.js';
2
+ export default function parseSheetData(state, sharedStrings, styles, epoch1904, options) {
3
+ return state.cells.map(function (_ref) {
4
+ var attributes = _ref.attributes,
5
+ value = _ref.value,
6
+ inlineString = _ref.inlineString;
7
+ return parseCell(attributes, value, inlineString, sharedStrings, styles, epoch1904, options);
8
+ });
9
+ }
10
+ export function createInitialStateInSheetData() {
11
+ return {
12
+ c: undefined,
13
+ cells: []
14
+ };
15
+ }
16
+ export function onOpenTagInSheetData(tagName, attributes, state) {
17
+ if (tagName === 'c') {
18
+ state.c = createInitialStateInCell();
19
+ state.c.attributes = attributes;
20
+ } else if (state.c) {
21
+ onOpenTagInCell(tagName, attributes, state.c);
22
+ }
23
+ }
24
+ export function onCloseTagInSheetData(tagName, state) {
25
+ if (tagName === 'c') {
26
+ state.cells.push({
27
+ attributes: state.c.attributes,
28
+ value: state.c.value,
29
+ inlineString: state.c.inlineString
30
+ });
31
+ state.c = undefined;
32
+ } else if (state.c) {
33
+ onCloseTagInCell(tagName, state.c);
34
+ }
35
+ }
36
+ export function onTextInSheetData(text, state) {
37
+ if (state.c) {
38
+ onTextInCell(text, state.c);
39
+ }
40
+ }
41
+
42
+ // Here, it could also parse "merged cells" and then return them in some special way.
43
+ // But then it's not clear what should be the way to return such merged cells.
44
+ // I.e. should it just return it as a duplicate value in each one of the merged cells?
45
+ // Or should it keep the current behavior of only returning the value of the top-most left-most cell
46
+ // and then just return `null` for the rest of the cells in a "merged cells" group?
47
+ // Perhaps the latter (current) approach is the most sensible one, so there's no need
48
+ // to change anything.
49
+ //
50
+ // const mergedCells = getMergedCellCoordinates(sheetDocument)
51
+ // for (const mergedCell of mergedCells) {
52
+ // const [from, to] = mergedCell.split(':').map(parseCellAddress)
53
+ // console.log('Merged Cell.', 'From:', from, 'To:', to)
54
+ // }
55
+ //# sourceMappingURL=parseSheetData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseSheetData.js","names":["parseCell","createInitialStateInCell","onOpenTagInCell","onCloseTagInCell","onTextInCell","parseSheetData","state","sharedStrings","styles","epoch1904","options","cells","map","_ref","attributes","value","inlineString","createInitialStateInSheetData","c","undefined","onOpenTagInSheetData","tagName","onCloseTagInSheetData","push","onTextInSheetData","text"],"sources":["../../source/xlsx/parseSheetData.js"],"sourcesContent":["import parseCell, {\r\n createInitialStateInCell,\r\n onOpenTagInCell,\r\n onCloseTagInCell,\r\n onTextInCell\r\n} from './parseCell.js'\r\n\r\nexport default function parseSheetData(state, sharedStrings, styles, epoch1904, options) {\r\n return state.cells.map(({ attributes, value, inlineString }) => {\r\n return parseCell(\r\n attributes,\r\n value,\r\n inlineString,\r\n sharedStrings,\r\n styles,\r\n epoch1904,\r\n options\r\n )\r\n })\r\n}\r\n\r\nexport function createInitialStateInSheetData() {\r\n return {\r\n c: undefined,\r\n cells: []\r\n }\r\n}\r\n\r\nexport function onOpenTagInSheetData(tagName, attributes, state) {\r\n if (tagName === 'c') {\r\n state.c = createInitialStateInCell()\r\n state.c.attributes = attributes\r\n } else if (state.c) {\r\n onOpenTagInCell(tagName, attributes, state.c)\r\n }\r\n}\r\n\r\nexport function onCloseTagInSheetData(tagName, state) {\r\n if (tagName === 'c') {\r\n state.cells.push({\r\n attributes: state.c.attributes,\r\n value: state.c.value,\r\n inlineString: state.c.inlineString\r\n })\r\n state.c = undefined\r\n } else if (state.c) {\r\n onCloseTagInCell(tagName, state.c)\r\n }\r\n}\r\n\r\nexport function onTextInSheetData(text, state) {\r\n if (state.c) {\r\n onTextInCell(text, state.c)\r\n }\r\n}\r\n\r\n// Here, it could also parse \"merged cells\" and then return them in some special way.\r\n// But then it's not clear what should be the way to return such merged cells.\r\n// I.e. should it just return it as a duplicate value in each one of the merged cells?\r\n// Or should it keep the current behavior of only returning the value of the top-most left-most cell\r\n// and then just return `null` for the rest of the cells in a \"merged cells\" group?\r\n// Perhaps the latter (current) approach is the most sensible one, so there's no need\r\n// to change anything.\r\n//\r\n// const mergedCells = getMergedCellCoordinates(sheetDocument)\r\n// for (const mergedCell of mergedCells) {\r\n// const [from, to] = mergedCell.split(':').map(parseCellAddress)\r\n// console.log('Merged Cell.', 'From:', from, 'To:', to)\r\n// }"],"mappings":"AAAA,OAAOA,SAAS,IACdC,wBAAwB,EACxBC,eAAe,EACfC,gBAAgB,EAChBC,YAAY,QACP,gBAAgB;AAEvB,eAAe,SAASC,cAAcA,CAACC,KAAK,EAAEC,aAAa,EAAEC,MAAM,EAAEC,SAAS,EAAEC,OAAO,EAAE;EACvF,OAAOJ,KAAK,CAACK,KAAK,CAACC,GAAG,CAAC,UAAAC,IAAA,EAAyC;IAAA,IAAtCC,UAAU,GAAAD,IAAA,CAAVC,UAAU;MAAEC,KAAK,GAAAF,IAAA,CAALE,KAAK;MAAEC,YAAY,GAAAH,IAAA,CAAZG,YAAY;IACvD,OAAOhB,SAAS,CACdc,UAAU,EACVC,KAAK,EACLC,YAAY,EACZT,aAAa,EACbC,MAAM,EACNC,SAAS,EACTC,OACF,CAAC;EACH,CAAC,CAAC;AACJ;AAEA,OAAO,SAASO,6BAA6BA,CAAA,EAAG;EAC9C,OAAO;IACLC,CAAC,EAAEC,SAAS;IACZR,KAAK,EAAE;EACT,CAAC;AACH;AAEA,OAAO,SAASS,oBAAoBA,CAACC,OAAO,EAAEP,UAAU,EAAER,KAAK,EAAE;EAC/D,IAAIe,OAAO,KAAK,GAAG,EAAE;IACnBf,KAAK,CAACY,CAAC,GAAGjB,wBAAwB,CAAC,CAAC;IACpCK,KAAK,CAACY,CAAC,CAACJ,UAAU,GAAGA,UAAU;EACjC,CAAC,MAAM,IAAIR,KAAK,CAACY,CAAC,EAAE;IAClBhB,eAAe,CAACmB,OAAO,EAAEP,UAAU,EAAER,KAAK,CAACY,CAAC,CAAC;EAC/C;AACF;AAEA,OAAO,SAASI,qBAAqBA,CAACD,OAAO,EAAEf,KAAK,EAAE;EACpD,IAAIe,OAAO,KAAK,GAAG,EAAE;IACnBf,KAAK,CAACK,KAAK,CAACY,IAAI,CAAC;MACfT,UAAU,EAAER,KAAK,CAACY,CAAC,CAACJ,UAAU;MAC9BC,KAAK,EAAET,KAAK,CAACY,CAAC,CAACH,KAAK;MACpBC,YAAY,EAAEV,KAAK,CAACY,CAAC,CAACF;IACxB,CAAC,CAAC;IACFV,KAAK,CAACY,CAAC,GAAGC,SAAS;EACrB,CAAC,MAAM,IAAIb,KAAK,CAACY,CAAC,EAAE;IAClBf,gBAAgB,CAACkB,OAAO,EAAEf,KAAK,CAACY,CAAC,CAAC;EACpC;AACF;AAEA,OAAO,SAASM,iBAAiBA,CAACC,IAAI,EAAEnB,KAAK,EAAE;EAC7C,IAAIA,KAAK,CAACY,CAAC,EAAE;IACXd,YAAY,CAACqB,IAAI,EAAEnB,KAAK,CAACY,CAAC,CAAC;EAC7B;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
@@ -1,66 +1,162 @@
1
+ var _excluded = ["parseNumber"];
2
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
1
3
  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."); }
2
4
  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); }
3
5
  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; }
6
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
7
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
8
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
12
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
4
13
  import parseSpreadsheetInfo from './parseSpreadsheetInfo.js';
5
14
  import parseFilePaths from './parseFilePaths.js';
6
15
  import parseStyles from './parseStyles.js';
7
16
  import parseSharedStrings from './parseSharedStrings.js';
8
17
  import parseSheet from './parseSheet.js';
18
+ import parseNumberDefault from './parseNumber.js';
19
+ import checkpoint, { latestCheckpointTimestamp } from '../utility/checkpoint.js';
20
+ import isPromise from '../utility/isPromise.js';
9
21
 
10
22
  // For an introduction in reading `.xlsx` files see "The minimum viable XLSX reader":
11
23
  // https://www.brendanlong.com/the-minimum-viable-xlsx-reader.html
12
24
 
13
25
  /**
14
26
  * Reads data from an `.xlsx` file.
27
+ * @param {function} parseXmlStream — SAX XML parser.
15
28
  * @param {Record<string,string>} contents - A map of `.xml` files inside the `.xlsx` file (which itself is just a zipped directory).
16
- * @param {object} xml — An object having a single property — `createDocument(string)` function.
17
29
  * @param {object} [options]
18
- * @return {Sheet[]}
30
+ * @return {Promise<Sheet[]>}
19
31
  */
20
- export default function parseSpreadsheetContents(contents, xml) {
32
+ function parseSpreadsheetContents(parseXmlStream, contents) {
21
33
  var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
22
- var getFileContent = function getFileContent(filePath) {
23
- if (!contents[filePath]) {
24
- throw new Error("\"".concat(filePath, "\" file not found inside the *.xlsx file zip archive"));
25
- }
26
- return contents[filePath];
27
- };
34
+ // Because of how `.xlsx` file contents are defined in the specification,
35
+ // it will have to be read in 3 passes:
36
+ // * First pass read the actual file paths
37
+ // * Second pass — read "shared strings" and "styles"
38
+ // * Thirs pass — read the sheets data
28
39
 
29
- // Read the paths to certain files inside the `.xlsx` file, which is itself just a `.zip` archive.
30
- // These paths aren't standardized between different spreadsheet editors.
31
- // https://github.com/tidyverse/readxl/issues/104
32
- var filePaths = parseFilePaths(getFileContent('xl/_rels/workbook.xml.rels'), xml);
33
-
34
- // The usual file path for "shared strings" is "xl/sharedStrings.xml".
35
- var sharedStrings = filePaths.sharedStrings ? parseSharedStrings(getFileContent(filePaths.sharedStrings), xml) : [];
36
-
37
- // The usual file path for "styles" is "xl/styles.xml".
38
- var styles = filePaths.styles ? parseStyles(getFileContent(filePaths.styles), xml) : {};
39
- var _parseSpreadsheetInfo = parseSpreadsheetInfo(getFileContent('xl/workbook.xml'), xml),
40
- sheets = _parseSpreadsheetInfo.sheets,
41
- epoch1904 = _parseSpreadsheetInfo.epoch1904;
42
- var sheetIdsToRead = options.sheets && options.sheets.map(function (sheet) {
43
- return getSheetId(sheet, sheets);
44
- });
40
+ checkpoint('parse spreadsheet info and file paths');
45
41
 
46
- // Parse sheets data.
42
+ // Get spreadsheet info and the paths to files.
43
+ return readFiles(getXmlFilesAtFixedPaths(), contents, parseXmlStream).then(function (_ref) {
44
+ var spreadsheetInfo = _ref.spreadsheetInfo,
45
+ filePaths = _ref.filePaths;
46
+ checkpoint('parse "shared strings" and "styles"');
47
47
 
48
- var sheetsData = [];
49
- for (var _i = 0, _Object$keys = Object.keys(filePaths.sheets); _i < _Object$keys.length; _i++) {
50
- var sheetId = _Object$keys[_i];
51
- if (sheetIdsToRead && !sheetIdsToRead.includes(sheetId)) {
52
- continue;
53
- }
54
- sheetsData.push({
55
- sheet: getSheetNameById(sheetId, sheets),
56
- data: parseSheet(getFileContent(filePaths.sheets[sheetId]), xml, sharedStrings, styles, epoch1904, options)
48
+ // Parse "shared strings" and "styles".
49
+ return readFiles(getXmlFilesAtNonFixedPaths(filePaths), contents, parseXmlStream).then(function (_ref2) {
50
+ var sharedStrings = _ref2.sharedStrings,
51
+ styles = _ref2.styles;
52
+ var sheetRelationIdsToRead = options.sheets ? options.sheets.map(function (sheet) {
53
+ return getSheetRelationId(sheet, spreadsheetInfo.sheets);
54
+ }) : spreadsheetInfo.sheets.map(function (_) {
55
+ return _.relationId;
56
+ });
57
+ checkpoint("parse sheet".concat(sheetRelationIdsToRead.length === 1 ? '' : 's', " data"));
58
+
59
+ // Parse sheets data.
60
+ return readFiles(getSheetDataXmlFiles(filePaths, sheetRelationIdsToRead, {
61
+ sharedStrings: sharedStrings,
62
+ styles: styles,
63
+ epoch1904: spreadsheetInfo.epoch1904,
64
+ options: options
65
+ }), contents, parseXmlStream).then(function (sheetsData) {
66
+ checkpoint('end');
67
+ // Return sheets data.
68
+ return sheetRelationIdsToRead.map(function (sheetRelationId) {
69
+ return {
70
+ sheet: getSheetNameByRelationId(sheetRelationId, spreadsheetInfo.sheets),
71
+ data: sheetsData[sheetRelationId]
72
+ };
73
+ });
74
+ });
75
+ });
76
+ });
77
+ }
78
+
79
+ /**
80
+ * Reads data from an `.xlsx` file in a worker.
81
+ * @param {function} [createWorkerFunction] — Creates a worker function.
82
+ * @param {function} parseXmlStream — SAX XML parser.
83
+ * @param {Record<string,string>} contents - A map of `.xml` files inside the `.xlsx` file (which itself is just a zipped directory).
84
+ * @param {object} [options]
85
+ * @return {Promise<Sheet[]>}
86
+ */
87
+ export default function parseSpreadsheetContentsInWorker(createWorkerFunction, parseXmlStream, contents, options) {
88
+ // Assign the default `parseNumber()` function in the `options`.
89
+ // The reason is that the worker code requires it to be non-`undefined`.
90
+ // Otherwise, it would throw "parseNumber is not defined".
91
+ if (!(options && options.parseNumber)) {
92
+ options = _objectSpread(_objectSpread({}, options), {}, {
93
+ parseNumber: parseNumberDefault
57
94
  });
58
95
  }
59
96
 
60
- // Return spreadsheet data.
61
- return sheetsData;
97
+ // Using a worker requires specifying all the top-level variables or functions that it uses.
98
+ // Currently, that list looks a little bit too long so for now workers aren't used for parsing sheet data.
99
+ // See the comment in `createWorkerFunction()` call for more details.
100
+ // createWorkerFunction = undefined
101
+
102
+ // If the environment doesn't support "workers", parse spreadsheet contents "synchronously".
103
+ // This will "block" the main thread while parsing.
104
+ if (!createWorkerFunction) {
105
+ return parseSpreadsheetContents(parseXmlStream, contents, options);
106
+ }
107
+
108
+ // Any functions have to be removed from the `options` in order for them to be "serializable"
109
+ // before sending them to the worker thread.
110
+ var _options = options,
111
+ parseNumber = _options.parseNumber,
112
+ optionsJson = _objectWithoutProperties(_options, _excluded);
113
+
114
+ // Create a worker.
115
+ var workerFn = createWorkerFunction(function (data) {
116
+ // Reconstruct the `options`.
117
+ var options = _objectSpread(_objectSpread({}, data.optionsJson), {}, {
118
+ parseNumber: parseNumber
119
+ });
120
+ // Parse sheet data from the `.xml` files.
121
+ return parseSpreadsheetContents(parseXmlStream, data.contents, options);
122
+ });
123
+ workerFn.addDependencies(
124
+ // Any "outside" dependencies that're referenced in the function (below).
125
+ function () {
126
+ return [parseXmlStream, parseNumber, parseSpreadsheetContents, getSheetRelationId, getSheetNameByRelationId, getXmlFilesAtFixedPaths, getXmlFilesAtNonFixedPaths, getSheetDataXmlFiles, readFiles, checkpoint, latestCheckpointTimestamp, isPromise
127
+ // parseSheet,
128
+ //
129
+ // This is not the full list by any means. There's more. Quite a lot more of them.
130
+ // It started looking a bit too much so I stopped adding the dependencies here.
131
+ // Now I understand why `fflate`'s source code is all written in a single
132
+ // multi-thousand-line `index.ts` file. The thing is, once one starts splitting
133
+ // the code into modules, they'd have to manually export any top-level variables
134
+ // or functions from those modules and import them here in order to specify them
135
+ // in the list of dependencies. And even if doing so for every top-level variable
136
+ // or function in every imported module doesn't seem like an impossible task,
137
+ // imagine someone refactoring the code later and extracting new top-level
138
+ // variables or functions. Without 100% code coverage requirement, it won't be caught
139
+ // at build time and can only be caught in production, which isn't ideal to say the least.
140
+ // So it seems like users of this package will have to just deal with the "blocking"
141
+ // nature of the sheet data parser, because I won't follow into `fflate`'s steps
142
+ // and rewrite this package as a single `index.js` file.
143
+ // Users of this package will have to manually put their code in a worker
144
+ // in case they'd prefer it to run in a separate thread to prevent "blocking"
145
+ // the main thread when parsing sheet data.
146
+ ];
147
+ });
148
+
149
+ // Post a message with some data to the worker
150
+ // so that it starts processing the data
151
+ // and later posts a message back to the main thread
152
+ // with the result of the calculation.
153
+ return workerFn.callOnce({
154
+ optionsJson: optionsJson,
155
+ contents: contents
156
+ }); // (optional) add `transferList` argument.
62
157
  }
63
- function getSheetId(sheet, sheets) {
158
+
159
+ function getSheetRelationId(sheet, sheets) {
64
160
  if (typeof sheet === 'string') {
65
161
  for (var _iterator = _createForOfIteratorHelperLoose(sheets), _step; !(_step = _iterator()).done;) {
66
162
  var _sheet = _step.value;
@@ -68,8 +164,8 @@ function getSheetId(sheet, sheets) {
68
164
  return _sheet.relationId;
69
165
  }
70
166
  }
71
- throw new Error("Sheet \"".concat(sheet, "\" not found. Available sheets: ").concat(sheets.map(function (_ref) {
72
- var name = _ref.name;
167
+ throw new Error("Sheet \"".concat(sheet, "\" not found. Available sheets: ").concat(sheets.map(function (_ref3) {
168
+ var name = _ref3.name;
73
169
  return "\"".concat(name, "\"");
74
170
  }).join(', ')));
75
171
  } else {
@@ -79,13 +175,116 @@ function getSheetId(sheet, sheets) {
79
175
  throw new Error("Sheet number out of bounds: ".concat(sheet, ". Available sheets count: ").concat(sheets.length));
80
176
  }
81
177
  }
82
- function getSheetNameById(sheetId, sheets) {
178
+ function getSheetNameByRelationId(sheetRelationId, sheets) {
83
179
  for (var _iterator2 = _createForOfIteratorHelperLoose(sheets), _step2; !(_step2 = _iterator2()).done;) {
84
180
  var sheet = _step2.value;
85
- if (sheet.relationId === sheetId) {
181
+ if (sheet.relationId === sheetRelationId) {
86
182
  return sheet.name;
87
183
  }
88
184
  }
89
- throw new Error("Sheet ID not found: ".concat(sheetId));
185
+ throw new Error("Sheet relation ID not found: ".concat(sheetRelationId));
186
+ }
187
+ function getXmlFilesAtFixedPaths() {
188
+ return {
189
+ // Read the paths to certain files inside the `.xlsx` file, which is itself just a `.zip` archive.
190
+ // These paths aren't standardized between different spreadsheet editors.
191
+ // https://github.com/tidyverse/readxl/issues/104
192
+ 'xl/_rels/workbook.xml.rels': {
193
+ name: 'filePaths',
194
+ parse: parseFilePaths
195
+ },
196
+ // General info on the spreadsheet.
197
+ 'xl/workbook.xml': {
198
+ name: 'spreadsheetInfo',
199
+ parse: parseSpreadsheetInfo
200
+ }
201
+ };
202
+ }
203
+ function getXmlFilesAtNonFixedPaths(filePaths) {
204
+ var _ref4;
205
+ return _ref4 = {}, _defineProperty(_ref4, filePaths.sharedStrings || 'xl/sharedStrings.xml', {
206
+ name: 'sharedStrings',
207
+ // `parseSharedStrings()` returns a `Promise`.
208
+ parse: parseSharedStrings,
209
+ // It seems that "sharedStrings.xml" is not required to exist.
210
+ // For example, that could be the case when a spreadsheet doesn't contain any strings.
211
+ // https://github.com/catamphetamine/read-excel-file/issues/85
212
+ fallback: []
213
+ }), _defineProperty(_ref4, filePaths.styles || 'xl/styles.xml', {
214
+ name: 'styles',
215
+ parse: parseStyles,
216
+ fallback: {}
217
+ }), _ref4;
218
+ }
219
+
220
+ // Returns the list of sheet data `.xml` files.
221
+ function getSheetDataXmlFiles(filePaths, sheetRelationIdsToRead, sheetDataParserParameters) {
222
+ return Object.keys(filePaths.sheets).filter(function (sheetRelationId) {
223
+ return sheetRelationIdsToRead.includes(sheetRelationId);
224
+ }).reduce(function (filesInfo, sheetRelationId) {
225
+ return _objectSpread(_objectSpread({}, filesInfo), {}, _defineProperty({}, filePaths.sheets[sheetRelationId], {
226
+ name: sheetRelationId,
227
+ // `parseSheet()` returns a `Promise`.
228
+ parse: function parse(content, parseXmlStream) {
229
+ return parseSheet(content, parseXmlStream, sheetDataParserParameters);
230
+ }
231
+ }));
232
+ }, {});
233
+ }
234
+
235
+ // In case of converting `.zip` file reader from a "read-and-return" one to a "streaming" one,
236
+ // this function could be modified to process the files as they come rather than all-at-once.
237
+
238
+ // Reads files from inside an `.xlsx` archive by file paths.
239
+ //
240
+ // In case of converting `.zip` file reader from a "read-and-return" one to a "streaming" one,
241
+ // this function could be modified to process the files as they come rather than all-at-once.
242
+ //
243
+ // But there's a catch: inside an `.xlsx` file, some file paths are not fixed
244
+ // and are instead defined in "xl/_rels/workbook.xml.rels" file,
245
+ // which presents a "chicken and an egg" dilemma: how could one possibly
246
+ // read an `.xlsx` file in one go when the order of the files inside it isn't fixed
247
+ // and could be random. Most likely, in the majority of cases, "xl/_rels/workbook.xml.rels"
248
+ // file is gonna be one of the first in a given `.xlsx` archive, but still it's not guaranteed.
249
+ // A solution would be reading an `.xlsx` file in two passes: one pass would be just to read
250
+ // the "xl/_rels/workbook.xml.rels" and ignore decompressing anything else,
251
+ // and then the second pass would be to read all other files whose paths are now known.
252
+ //
253
+ // Returns:
254
+ // * If none of the `parse()` functions returned a `Promise`, it returns a map of files' contents.
255
+ // * If any of the `parse()` functions returned a `Promise`, it returns a `Promise` that resolves to a map of files' contents.
256
+ //
257
+ function readFiles(filesInfo, contents, parseXmlStream) {
258
+ // Get files' contents.
259
+ var results = {};
260
+ var _loop = function _loop() {
261
+ var filePath = _Object$keys[_i];
262
+ var fileInfo = filesInfo[filePath];
263
+ results[fileInfo.name] = contents[filePath] === undefined ? fileInfo.fallback === undefined ? function () {
264
+ throw new Error("\"".concat(filePath, "\" file not found inside the `.xlsx` file"));
265
+ }() : fileInfo.fallback : fileInfo.parse(contents[filePath], parseXmlStream);
266
+ };
267
+ for (var _i = 0, _Object$keys = Object.keys(filesInfo); _i < _Object$keys.length; _i++) {
268
+ _loop();
269
+ }
270
+ // Resolve any `Promise`s.
271
+ var promises = [];
272
+ var _loop2 = function _loop2() {
273
+ var name = _Object$keys2[_i2];
274
+ if (isPromise(results[name])) {
275
+ promises.push(results[name].then(function (result) {
276
+ results[name] = result;
277
+ }));
278
+ }
279
+ };
280
+ for (var _i2 = 0, _Object$keys2 = Object.keys(results); _i2 < _Object$keys2.length; _i2++) {
281
+ _loop2();
282
+ }
283
+ if (promises.length > 0) {
284
+ return Promise.all(promises).then(function () {
285
+ return results;
286
+ });
287
+ }
288
+ return results;
90
289
  }
91
290
  //# sourceMappingURL=parseSpreadsheetContents.js.map