read-excel-file 7.0.2 → 8.0.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 (266) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +212 -205
  3. package/browser/index.cjs +8 -5
  4. package/browser/index.d.ts +58 -16
  5. package/browser/index.js +7 -5
  6. package/browser/input.d.ts +1 -0
  7. package/bundle/read-excel-file.min.js +1 -1
  8. package/bundle/read-excel-file.min.js.map +1 -1
  9. package/commonjs/export/parseSheet.js +20 -0
  10. package/commonjs/export/parseSheet.js.map +1 -0
  11. package/commonjs/export/readSheetBrowser.js +29 -0
  12. package/commonjs/export/readSheetBrowser.js.map +1 -0
  13. package/commonjs/export/readSheetNode.js +29 -0
  14. package/commonjs/export/readSheetNode.js.map +1 -0
  15. package/commonjs/export/readSheetUniversal.js +29 -0
  16. package/commonjs/export/readSheetUniversal.js.map +1 -0
  17. package/commonjs/export/readSheetWebWorker.js +29 -0
  18. package/commonjs/export/readSheetWebWorker.js.map +1 -0
  19. package/commonjs/export/readXlsxFileBrowser.js +6 -8
  20. package/commonjs/export/readXlsxFileBrowser.js.map +1 -1
  21. package/commonjs/export/readXlsxFileNode.js +7 -9
  22. package/commonjs/export/readXlsxFileNode.js.map +1 -1
  23. package/commonjs/export/readXlsxFileUniversal.js +7 -9
  24. package/commonjs/export/readXlsxFileUniversal.js.map +1 -1
  25. package/commonjs/export/readXlsxFileWebWorker.js +6 -8
  26. package/commonjs/export/readXlsxFileWebWorker.js.map +1 -1
  27. package/commonjs/export/unpackXlsxFileBrowser.js +2 -1
  28. package/commonjs/export/unpackXlsxFileBrowser.js.map +1 -1
  29. package/commonjs/export/unpackXlsxFileNode.js +4 -3
  30. package/commonjs/export/unpackXlsxFileNode.js.map +1 -1
  31. package/commonjs/export/unpackXlsxFileUniversal.js +13 -3
  32. package/commonjs/export/unpackXlsxFileUniversal.js.map +1 -1
  33. package/commonjs/parseData/InvalidError.js.map +1 -0
  34. package/commonjs/parseData/parseData.js +503 -0
  35. package/commonjs/parseData/parseData.js.map +1 -0
  36. package/commonjs/parseData/parseData.test.js.map +1 -0
  37. package/commonjs/{types → parseData/types}/Boolean.js +1 -1
  38. package/commonjs/parseData/types/Boolean.js.map +1 -0
  39. package/commonjs/parseData/types/Date.js +21 -0
  40. package/commonjs/parseData/types/Date.js.map +1 -0
  41. package/commonjs/{types → parseData/types}/Number.js +1 -1
  42. package/commonjs/parseData/types/Number.js.map +1 -0
  43. package/commonjs/{types → parseData/types}/String.js +1 -1
  44. package/commonjs/parseData/types/String.js.map +1 -0
  45. package/commonjs/{types → parseData/types/additional}/Email.js +3 -3
  46. package/commonjs/parseData/types/additional/Email.js.map +1 -0
  47. package/commonjs/parseData/types/additional/Email.test.js.map +1 -0
  48. package/commonjs/{types → parseData/types/additional}/Integer.js +2 -2
  49. package/commonjs/parseData/types/additional/Integer.js.map +1 -0
  50. package/commonjs/parseData/types/additional/Integer.test.js.map +1 -0
  51. package/commonjs/{types → parseData/types/additional}/URL.js +3 -3
  52. package/commonjs/parseData/types/additional/URL.js.map +1 -0
  53. package/commonjs/parseData/types/additional/URL.test.js.map +1 -0
  54. package/commonjs/xlsx/{getData.js → convertCellsToData2dArray.js} +16 -37
  55. package/commonjs/xlsx/convertCellsToData2dArray.js.map +1 -0
  56. package/commonjs/xlsx/{isDateTimestamp.js → isDateFormat.js} +58 -56
  57. package/commonjs/xlsx/isDateFormat.js.map +1 -0
  58. package/commonjs/xlsx/isDateFormat.test.js.map +1 -0
  59. package/commonjs/xlsx/isDateFormatStyle.js +193 -0
  60. package/commonjs/xlsx/isDateFormatStyle.js.map +1 -0
  61. package/commonjs/xlsx/parseCell.js +16 -18
  62. package/commonjs/xlsx/parseCell.js.map +1 -1
  63. package/commonjs/xlsx/parseCellCoordinates.js +44 -0
  64. package/commonjs/xlsx/parseCellCoordinates.js.map +1 -0
  65. package/commonjs/xlsx/parseCellValue.js +14 -11
  66. package/commonjs/xlsx/parseCellValue.js.map +1 -1
  67. package/commonjs/xlsx/parseCells.js +14 -6
  68. package/commonjs/xlsx/parseCells.js.map +1 -1
  69. package/commonjs/xlsx/parseExcelDate.js +139 -0
  70. package/commonjs/xlsx/parseExcelDate.js.map +1 -0
  71. package/commonjs/xlsx/parseExcelDate.test.js.map +1 -0
  72. package/commonjs/xlsx/parseSheet.js +9 -11
  73. package/commonjs/xlsx/parseSheet.js.map +1 -1
  74. package/commonjs/xlsx/{parseDimensions.js → parseSheetDimensions.js} +7 -6
  75. package/commonjs/xlsx/parseSheetDimensions.js.map +1 -0
  76. package/commonjs/xlsx/parseSpreadsheetContents.js +96 -0
  77. package/commonjs/xlsx/parseSpreadsheetContents.js.map +1 -0
  78. package/commonjs/xlsx/parseSpreadsheetInfo.js +47 -0
  79. package/commonjs/xlsx/parseSpreadsheetInfo.js.map +1 -0
  80. package/commonjs/xlsx/reconstructSheetDimensionsFromSheetCells.js +29 -0
  81. package/commonjs/xlsx/reconstructSheetDimensionsFromSheetCells.js.map +1 -0
  82. package/commonjs/xml/xlsx.js +9 -9
  83. package/commonjs/xml/xlsx.js.map +1 -1
  84. package/commonjs/xml/xpath/xlsx-xpath.js +8 -8
  85. package/commonjs/xml/xpath/xlsx-xpath.js.map +1 -1
  86. package/commonjs/xml/xpath/xpathBrowser.js +4 -4
  87. package/commonjs/xml/xpath/xpathBrowser.js.map +1 -1
  88. package/commonjs/xml/xpath/xpathNode.js +2 -2
  89. package/commonjs/xml/xpath/xpathNode.js.map +1 -1
  90. package/modules/export/parseSheet.js +13 -0
  91. package/modules/export/parseSheet.js.map +1 -0
  92. package/modules/export/readSheetBrowser.js +23 -0
  93. package/modules/export/readSheetBrowser.js.map +1 -0
  94. package/modules/export/readSheetNode.js +23 -0
  95. package/modules/export/readSheetNode.js.map +1 -0
  96. package/modules/export/readSheetUniversal.js +23 -0
  97. package/modules/export/readSheetUniversal.js.map +1 -0
  98. package/modules/export/readSheetWebWorker.js +23 -0
  99. package/modules/export/readSheetWebWorker.js.map +1 -0
  100. package/modules/export/readXlsxFileBrowser.js +6 -8
  101. package/modules/export/readXlsxFileBrowser.js.map +1 -1
  102. package/modules/export/readXlsxFileNode.js +7 -9
  103. package/modules/export/readXlsxFileNode.js.map +1 -1
  104. package/modules/export/readXlsxFileUniversal.js +7 -9
  105. package/modules/export/readXlsxFileUniversal.js.map +1 -1
  106. package/modules/export/readXlsxFileWebWorker.js +6 -8
  107. package/modules/export/readXlsxFileWebWorker.js.map +1 -1
  108. package/modules/export/unpackXlsxFileBrowser.js +3 -1
  109. package/modules/export/unpackXlsxFileBrowser.js.map +1 -1
  110. package/modules/export/unpackXlsxFileNode.js +4 -3
  111. package/modules/export/unpackXlsxFileNode.js.map +1 -1
  112. package/modules/export/unpackXlsxFileUniversal.js +13 -3
  113. package/modules/export/unpackXlsxFileUniversal.js.map +1 -1
  114. package/modules/parseData/InvalidError.js.map +1 -0
  115. package/modules/parseData/parseData.js +494 -0
  116. package/modules/parseData/parseData.js.map +1 -0
  117. package/modules/parseData/parseData.test.js.map +1 -0
  118. package/modules/{types → parseData/types}/Boolean.js +1 -1
  119. package/modules/parseData/types/Boolean.js.map +1 -0
  120. package/modules/parseData/types/Date.js +14 -0
  121. package/modules/parseData/types/Date.js.map +1 -0
  122. package/modules/{types → parseData/types}/Number.js +1 -1
  123. package/modules/parseData/types/Number.js.map +1 -0
  124. package/modules/{types → parseData/types}/String.js +1 -1
  125. package/modules/parseData/types/String.js.map +1 -0
  126. package/modules/{types → parseData/types/additional}/Email.js +3 -3
  127. package/modules/parseData/types/additional/Email.js.map +1 -0
  128. package/modules/parseData/types/additional/Email.test.js.map +1 -0
  129. package/modules/{types → parseData/types/additional}/Integer.js +2 -2
  130. package/modules/parseData/types/additional/Integer.js.map +1 -0
  131. package/modules/parseData/types/additional/Integer.test.js.map +1 -0
  132. package/modules/{types → parseData/types/additional}/URL.js +3 -3
  133. package/modules/parseData/types/additional/URL.js.map +1 -0
  134. package/modules/parseData/types/additional/URL.test.js.map +1 -0
  135. package/modules/xlsx/{getData.js → convertCellsToData2dArray.js} +15 -36
  136. package/modules/xlsx/convertCellsToData2dArray.js.map +1 -0
  137. package/modules/xlsx/{isDateTimestamp.js → isDateFormat.js} +57 -55
  138. package/modules/xlsx/isDateFormat.js.map +1 -0
  139. package/modules/xlsx/isDateFormat.test.js.map +1 -0
  140. package/modules/xlsx/isDateFormatStyle.js +186 -0
  141. package/modules/xlsx/isDateFormatStyle.js.map +1 -0
  142. package/modules/xlsx/parseCell.js +17 -19
  143. package/modules/xlsx/parseCell.js.map +1 -1
  144. package/modules/xlsx/parseCellCoordinates.js +38 -0
  145. package/modules/xlsx/parseCellCoordinates.js.map +1 -0
  146. package/modules/xlsx/parseCellValue.js +14 -11
  147. package/modules/xlsx/parseCellValue.js.map +1 -1
  148. package/modules/xlsx/parseCells.js +14 -6
  149. package/modules/xlsx/parseCells.js.map +1 -1
  150. package/modules/xlsx/parseExcelDate.js +133 -0
  151. package/modules/xlsx/parseExcelDate.js.map +1 -0
  152. package/modules/xlsx/parseExcelDate.test.js.map +1 -0
  153. package/modules/xlsx/parseSheet.js +9 -11
  154. package/modules/xlsx/parseSheet.js.map +1 -1
  155. package/modules/xlsx/{parseDimensions.js → parseSheetDimensions.js} +4 -4
  156. package/modules/xlsx/parseSheetDimensions.js.map +1 -0
  157. package/modules/xlsx/parseSpreadsheetContents.js +91 -0
  158. package/modules/xlsx/parseSpreadsheetContents.js.map +1 -0
  159. package/modules/xlsx/parseSpreadsheetInfo.js +42 -0
  160. package/modules/xlsx/parseSpreadsheetInfo.js.map +1 -0
  161. package/modules/xlsx/reconstructSheetDimensionsFromSheetCells.js +23 -0
  162. package/modules/xlsx/reconstructSheetDimensionsFromSheetCells.js.map +1 -0
  163. package/modules/xml/xlsx.js +6 -6
  164. package/modules/xml/xlsx.js.map +1 -1
  165. package/modules/xml/xpath/xlsx-xpath.js +6 -6
  166. package/modules/xml/xpath/xlsx-xpath.js.map +1 -1
  167. package/modules/xml/xpath/xpathBrowser.js +4 -4
  168. package/modules/xml/xpath/xpathBrowser.js.map +1 -1
  169. package/modules/xml/xpath/xpathNode.js +2 -2
  170. package/modules/xml/xpath/xpathNode.js.map +1 -1
  171. package/node/index.cjs +8 -5
  172. package/node/index.d.ts +56 -21
  173. package/node/index.js +7 -5
  174. package/node/input.d.ts +5 -0
  175. package/package.json +1 -1
  176. package/rollup.config.mjs +1 -1
  177. package/types/parseData/parseData.d.ts +38 -0
  178. package/types/parseData/parseDataError.d.ts +239 -0
  179. package/types/parseData/parseDataSchema.d.ts +48 -0
  180. package/types/parseData/parseDataValueType.d.ts +45 -0
  181. package/types/types.d.ts +20 -0
  182. package/universal/index.cjs +8 -5
  183. package/universal/index.d.ts +58 -16
  184. package/universal/index.js +7 -5
  185. package/universal/input.d.ts +1 -0
  186. package/web-worker/index.cjs +8 -5
  187. package/web-worker/index.d.ts +58 -16
  188. package/web-worker/index.js +7 -5
  189. package/web-worker/input.d.ts +1 -0
  190. package/commonjs/export/readSheetNamesBrowser.js +0 -23
  191. package/commonjs/export/readSheetNamesBrowser.js.map +0 -1
  192. package/commonjs/export/readSheetNamesNode.js +0 -23
  193. package/commonjs/export/readSheetNamesNode.js.map +0 -1
  194. package/commonjs/export/readSheetNamesUniversal.js +0 -23
  195. package/commonjs/export/readSheetNamesUniversal.js.map +0 -1
  196. package/commonjs/export/readSheetNamesWebWorker.js +0 -23
  197. package/commonjs/export/readSheetNamesWebWorker.js.map +0 -1
  198. package/commonjs/types/Boolean.js.map +0 -1
  199. package/commonjs/types/Date.js +0 -36
  200. package/commonjs/types/Date.js.map +0 -1
  201. package/commonjs/types/Email.js.map +0 -1
  202. package/commonjs/types/Email.test.js.map +0 -1
  203. package/commonjs/types/Integer.js.map +0 -1
  204. package/commonjs/types/Integer.test.js.map +0 -1
  205. package/commonjs/types/InvalidError.js.map +0 -1
  206. package/commonjs/types/Number.js.map +0 -1
  207. package/commonjs/types/String.js.map +0 -1
  208. package/commonjs/types/URL.js.map +0 -1
  209. package/commonjs/types/URL.test.js.map +0 -1
  210. package/commonjs/xlsx/coordinates.js +0 -55
  211. package/commonjs/xlsx/coordinates.js.map +0 -1
  212. package/commonjs/xlsx/getData.js.map +0 -1
  213. package/commonjs/xlsx/isDateTimestamp.js.map +0 -1
  214. package/commonjs/xlsx/parseDate.js +0 -73
  215. package/commonjs/xlsx/parseDate.js.map +0 -1
  216. package/commonjs/xlsx/parseDate.test.js.map +0 -1
  217. package/commonjs/xlsx/parseDimensions.js.map +0 -1
  218. package/commonjs/xlsx/parseProperties.js +0 -46
  219. package/commonjs/xlsx/parseProperties.js.map +0 -1
  220. package/commonjs/xlsx/parseXlsxFileContents.js +0 -119
  221. package/commonjs/xlsx/parseXlsxFileContents.js.map +0 -1
  222. package/commonjs/xlsx/parseXlsxFileContentsWithOptionalSchema.js +0 -45
  223. package/commonjs/xlsx/parseXlsxFileContentsWithOptionalSchema.js.map +0 -1
  224. package/commonjs/xlsx/schema/mapToObjects.js +0 -482
  225. package/commonjs/xlsx/schema/mapToObjects.js.map +0 -1
  226. package/commonjs/xlsx/schema/mapToObjects.test.js.map +0 -1
  227. package/modules/export/readSheetNamesBrowser.js +0 -17
  228. package/modules/export/readSheetNamesBrowser.js.map +0 -1
  229. package/modules/export/readSheetNamesNode.js +0 -17
  230. package/modules/export/readSheetNamesNode.js.map +0 -1
  231. package/modules/export/readSheetNamesUniversal.js +0 -17
  232. package/modules/export/readSheetNamesUniversal.js.map +0 -1
  233. package/modules/export/readSheetNamesWebWorker.js +0 -17
  234. package/modules/export/readSheetNamesWebWorker.js.map +0 -1
  235. package/modules/types/Boolean.js.map +0 -1
  236. package/modules/types/Date.js +0 -29
  237. package/modules/types/Date.js.map +0 -1
  238. package/modules/types/Email.js.map +0 -1
  239. package/modules/types/Email.test.js.map +0 -1
  240. package/modules/types/Integer.js.map +0 -1
  241. package/modules/types/Integer.test.js.map +0 -1
  242. package/modules/types/InvalidError.js.map +0 -1
  243. package/modules/types/Number.js.map +0 -1
  244. package/modules/types/String.js.map +0 -1
  245. package/modules/types/URL.js.map +0 -1
  246. package/modules/types/URL.test.js.map +0 -1
  247. package/modules/xlsx/coordinates.js +0 -48
  248. package/modules/xlsx/coordinates.js.map +0 -1
  249. package/modules/xlsx/getData.js.map +0 -1
  250. package/modules/xlsx/isDateTimestamp.js.map +0 -1
  251. package/modules/xlsx/parseDate.js +0 -67
  252. package/modules/xlsx/parseDate.js.map +0 -1
  253. package/modules/xlsx/parseDate.test.js.map +0 -1
  254. package/modules/xlsx/parseDimensions.js.map +0 -1
  255. package/modules/xlsx/parseProperties.js +0 -41
  256. package/modules/xlsx/parseProperties.js.map +0 -1
  257. package/modules/xlsx/parseXlsxFileContents.js +0 -114
  258. package/modules/xlsx/parseXlsxFileContents.js.map +0 -1
  259. package/modules/xlsx/parseXlsxFileContentsWithOptionalSchema.js +0 -39
  260. package/modules/xlsx/parseXlsxFileContentsWithOptionalSchema.js.map +0 -1
  261. package/modules/xlsx/schema/mapToObjects.js +0 -472
  262. package/modules/xlsx/schema/mapToObjects.js.map +0 -1
  263. package/modules/xlsx/schema/mapToObjects.test.js.map +0 -1
  264. package/types.d.ts +0 -121
  265. /package/commonjs/{types → parseData}/InvalidError.js +0 -0
  266. /package/modules/{types → parseData}/InvalidError.js +0 -0
@@ -1,114 +0,0 @@
1
- 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); }
2
- 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."); }
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 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; }
6
- 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; }
7
- 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; }
8
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
9
- 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); }
10
- import parseProperties from './parseProperties.js';
11
- import parseFilePaths from './parseFilePaths.js';
12
- import parseStyles from './parseStyles.js';
13
- import parseSharedStrings from './parseSharedStrings.js';
14
- import parseSheet from './parseSheet.js';
15
- import getData from './getData.js';
16
-
17
- // For an introduction in reading `*.xlsx` files see "The minimum viable XLSX reader":
18
- // https://www.brendanlong.com/the-minimum-viable-xlsx-reader.html
19
-
20
- /**
21
- * Reads data from an `.xlsx` spreadsheet.
22
- * @param {Record<string,string>} contents - A map of XML files inside XLSX file (which is just a zipped directory).
23
- * @param {object} xml — An object with a function `createDocument(string)`.
24
- * @param {number?} options.sheet - Workbook sheet id (`1` by default).
25
- * @param {string?} options.dateFormat - Date format, e.g. "mm/dd/yyyy". Values having this format template set will be parsed as dates.
26
- * @return {object} An object of shape `{ data, cells, properties }`. `data: string[][]` is an array of rows, each row being an array of cell values. `cells: string[][]` is an array of rows, each row being an array of cells. `properties: object` is the spreadsheet properties (e.g. whether date epoch is 1904 instead of 1900).
27
- */
28
- export default function parseXlsxFileContents(contents, xml) {
29
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
30
- if (!options.sheet) {
31
- options = _objectSpread({
32
- sheet: 1
33
- }, options);
34
- }
35
- var getXmlFileContent = function getXmlFileContent(filePath) {
36
- if (!contents[filePath]) {
37
- throw new Error("\"".concat(filePath, "\" file not found inside the *.xlsx file zip archive"));
38
- }
39
- return contents[filePath];
40
- };
41
-
42
- // Read the paths to certain files inside the `.xlsx` `.zip` archive.
43
- // These paths aren't standardized between different spreadsheet editors.
44
- // https://github.com/tidyverse/readxl/issues/104
45
- var filePaths = parseFilePaths(getXmlFileContent('xl/_rels/workbook.xml.rels'), xml);
46
-
47
- // Usual file path for "shared strings": "xl/sharedStrings.xml".
48
- var values = filePaths.sharedStrings ? parseSharedStrings(getXmlFileContent(filePaths.sharedStrings), xml) : [];
49
-
50
- // Usual file path for "styles": "xl/styles.xml".
51
- var styles = filePaths.styles ? parseStyles(getXmlFileContent(filePaths.styles), xml) : {};
52
- var properties = parseProperties(getXmlFileContent('xl/workbook.xml'), xml);
53
-
54
- // A feature for getting the list of sheets in an Excel file.
55
- // https://github.com/catamphetamine/read-excel-file/issues/14
56
- if (options.getSheets) {
57
- return properties.sheets.map(function (_ref) {
58
- var name = _ref.name;
59
- return {
60
- name: name
61
- };
62
- });
63
- }
64
-
65
- // Find the sheet by name, or take the first one.
66
- var sheetId = getSheetId(options.sheet, properties.sheets);
67
-
68
- // If the sheet wasn't found then throw an error.
69
- // Example: "xl/worksheets/sheet1.xml".
70
- if (!sheetId || !filePaths.sheets[sheetId]) {
71
- throw createSheetNotFoundError(options.sheet, properties.sheets);
72
- }
73
-
74
- // Parse sheet data.
75
- var sheet = parseSheet(getXmlFileContent(filePaths.sheets[sheetId]), xml, values, styles, properties, options);
76
- options = _objectSpread({
77
- // Create a `rowIndexSourceMap` for the original dataset, if not passed,
78
- // because "empty" rows will be dropped from the input data.
79
- rowIndexSourceMap: []
80
- }, options);
81
-
82
- // Get spreadsheet data.
83
- var data = getData(sheet, options);
84
-
85
- // Can return properties, if required.
86
- if (options.properties) {
87
- return {
88
- data: data,
89
- properties: properties
90
- };
91
- }
92
-
93
- // Return spreadsheet data.
94
- return data;
95
- }
96
- function getSheetId(sheet, sheets) {
97
- if (typeof sheet === 'number') {
98
- var _sheet = sheets[sheet - 1];
99
- return _sheet && _sheet.relationId;
100
- }
101
- for (var _iterator = _createForOfIteratorHelperLoose(sheets), _step; !(_step = _iterator()).done;) {
102
- var _sheet2 = _step.value;
103
- if (_sheet2.name === sheet) {
104
- return _sheet2.relationId;
105
- }
106
- }
107
- }
108
- function createSheetNotFoundError(sheet, sheets) {
109
- var sheetsList = sheets && sheets.map(function (sheet, i) {
110
- return "\"".concat(sheet.name, "\" (#").concat(i + 1, ")");
111
- }).join(', ');
112
- return new Error("Sheet ".concat(typeof sheet === 'number' ? '#' + sheet : '"' + sheet + '"', " not found in the *.xlsx file.").concat(sheets ? ' Available sheets: ' + sheetsList + '.' : ''));
113
- }
114
- //# sourceMappingURL=parseXlsxFileContents.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseXlsxFileContents.js","names":["parseProperties","parseFilePaths","parseStyles","parseSharedStrings","parseSheet","getData","parseXlsxFileContents","contents","xml","options","arguments","length","undefined","sheet","_objectSpread","getXmlFileContent","filePath","Error","concat","filePaths","values","sharedStrings","styles","properties","getSheets","sheets","map","_ref","name","sheetId","getSheetId","createSheetNotFoundError","rowIndexSourceMap","data","_sheet","relationId","_iterator","_createForOfIteratorHelperLoose","_step","done","value","sheetsList","i","join"],"sources":["../../source/xlsx/parseXlsxFileContents.js"],"sourcesContent":["import parseProperties from './parseProperties.js'\r\nimport parseFilePaths from './parseFilePaths.js'\r\nimport parseStyles from './parseStyles.js'\r\nimport parseSharedStrings from './parseSharedStrings.js'\r\nimport parseSheet from './parseSheet.js'\r\nimport getData from './getData.js'\r\n\r\n// For an introduction in reading `*.xlsx` files see \"The minimum viable XLSX reader\":\r\n// https://www.brendanlong.com/the-minimum-viable-xlsx-reader.html\r\n\r\n/**\r\n * Reads data from an `.xlsx` spreadsheet.\r\n * @param {Record<string,string>} contents - A map of XML files inside XLSX file (which is just a zipped directory).\r\n * @param {object} xml — An object with a function `createDocument(string)`.\r\n * @param {number?} options.sheet - Workbook sheet id (`1` by default).\r\n * @param {string?} options.dateFormat - Date format, e.g. \"mm/dd/yyyy\". Values having this format template set will be parsed as dates.\r\n * @return {object} An object of shape `{ data, cells, properties }`. `data: string[][]` is an array of rows, each row being an array of cell values. `cells: string[][]` is an array of rows, each row being an array of cells. `properties: object` is the spreadsheet properties (e.g. whether date epoch is 1904 instead of 1900).\r\n */\r\nexport default function parseXlsxFileContents(contents, xml, options = {}) {\r\n if (!options.sheet) {\r\n options = {\r\n sheet: 1,\r\n ...options\r\n }\r\n }\r\n\r\n const getXmlFileContent = (filePath) => {\r\n if (!contents[filePath]) {\r\n throw new Error(`\"${filePath}\" file not found inside the *.xlsx file zip archive`)\r\n }\r\n return contents[filePath]\r\n }\r\n\r\n // Read the paths to certain files inside the `.xlsx` `.zip` archive.\r\n // These paths aren't standardized between different spreadsheet editors.\r\n // https://github.com/tidyverse/readxl/issues/104\r\n const filePaths = parseFilePaths(getXmlFileContent('xl/_rels/workbook.xml.rels'), xml)\r\n\r\n // Usual file path for \"shared strings\": \"xl/sharedStrings.xml\".\r\n const values = filePaths.sharedStrings\r\n ? parseSharedStrings(getXmlFileContent(filePaths.sharedStrings), xml)\r\n : []\r\n\r\n // Usual file path for \"styles\": \"xl/styles.xml\".\r\n const styles = filePaths.styles\r\n ? parseStyles(getXmlFileContent(filePaths.styles), xml)\r\n : {}\r\n\r\n const properties = parseProperties(getXmlFileContent('xl/workbook.xml'), xml)\r\n\r\n // A feature for getting the list of sheets in an Excel file.\r\n // https://github.com/catamphetamine/read-excel-file/issues/14\r\n if (options.getSheets) {\r\n return properties.sheets.map(({ name }) => ({\r\n name\r\n }))\r\n }\r\n\r\n // Find the sheet by name, or take the first one.\r\n const sheetId = getSheetId(options.sheet, properties.sheets)\r\n\r\n // If the sheet wasn't found then throw an error.\r\n // Example: \"xl/worksheets/sheet1.xml\".\r\n if (!sheetId || !filePaths.sheets[sheetId]) {\r\n throw createSheetNotFoundError(options.sheet, properties.sheets)\r\n }\r\n\r\n // Parse sheet data.\r\n const sheet = parseSheet(\r\n getXmlFileContent(filePaths.sheets[sheetId]),\r\n xml,\r\n values,\r\n styles,\r\n properties,\r\n options\r\n )\r\n\r\n options = {\r\n // Create a `rowIndexSourceMap` for the original dataset, if not passed,\r\n // because \"empty\" rows will be dropped from the input data.\r\n rowIndexSourceMap: [],\r\n ...options\r\n }\r\n\r\n // Get spreadsheet data.\r\n const data = getData(sheet, options)\r\n\r\n // Can return properties, if required.\r\n if (options.properties) {\r\n return {\r\n data,\r\n properties\r\n }\r\n }\r\n\r\n // Return spreadsheet data.\r\n return data\r\n}\r\n\r\nfunction getSheetId(sheet, sheets) {\r\n if (typeof sheet === 'number') {\r\n const _sheet = sheets[sheet - 1]\r\n return _sheet && _sheet.relationId\r\n }\r\n for (const _sheet of sheets) {\r\n if (_sheet.name === sheet) {\r\n return _sheet.relationId\r\n }\r\n }\r\n}\r\n\r\nfunction createSheetNotFoundError(sheet, sheets) {\r\n const sheetsList = sheets && sheets.map((sheet, i) => `\"${sheet.name}\" (#${i + 1})`).join(', ')\r\n return new Error(`Sheet ${typeof sheet === 'number' ? '#' + sheet : '\"' + sheet + '\"'} not found in the *.xlsx file.${sheets ? ' Available sheets: ' + sheetsList + '.' : ''}`)\r\n}"],"mappings":"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"}
@@ -1,39 +0,0 @@
1
- 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); }
2
- var _excluded = ["schema"];
3
- 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; }
4
- 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; }
5
- 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; }
6
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
- 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); }
8
- 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; }
9
- 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; }
10
- import parseXlsxFileContents from './parseXlsxFileContents.js';
11
- import mapToObjects from './schema/mapToObjects.js';
12
-
13
- /**
14
- * Reads data from an `.xlsx` spreadsheet.
15
- * @param {Record<string,string>} contents — A map of XML files inside XLSX file (which is just a zipped directory).
16
- * @param {object} xml — An object with a function `createDocument(string)`.
17
- * @param {object} options
18
- * @returns Spreadsheet data
19
- */
20
- export default function parseXlsxFileContentsWithOptionalSchema(contents, xml, _ref) {
21
- var schema = _ref.schema,
22
- options = _objectWithoutProperties(_ref, _excluded);
23
- if (options.map) {
24
- throw new Error('`map` option was removed. Pass a `schema` option instead.');
25
- }
26
- // `parseXlsxFileContents()` function creates `options.rowIndexSourceMap` property.
27
- // It maps parsed data row indexes to spreadsheet row indexes.
28
- // That's because empty rows are ignored (discarded) when parsing using `schema`.
29
- var result = parseXlsxFileContents(contents, xml, _objectSpread(_objectSpread({}, options), {}, {
30
- properties: schema || options.properties
31
- }));
32
- if (schema) {
33
- return mapToObjects(result.data, schema, _objectSpread(_objectSpread({}, options), {}, {
34
- properties: result.properties
35
- }));
36
- }
37
- return result;
38
- }
39
- //# sourceMappingURL=parseXlsxFileContentsWithOptionalSchema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parseXlsxFileContentsWithOptionalSchema.js","names":["parseXlsxFileContents","mapToObjects","parseXlsxFileContentsWithOptionalSchema","contents","xml","_ref","schema","options","_objectWithoutProperties","_excluded","map","Error","result","_objectSpread","properties","data"],"sources":["../../source/xlsx/parseXlsxFileContentsWithOptionalSchema.js"],"sourcesContent":["import parseXlsxFileContents from './parseXlsxFileContents.js'\r\n\r\nimport mapToObjects from './schema/mapToObjects.js'\r\n\r\n/**\r\n * Reads data from an `.xlsx` spreadsheet.\r\n * @param {Record<string,string>} contents — A map of XML files inside XLSX file (which is just a zipped directory).\r\n * @param {object} xml — An object with a function `createDocument(string)`.\r\n * @param {object} options\r\n * @returns Spreadsheet data\r\n */\r\nexport default function parseXlsxFileContentsWithOptionalSchema(contents, xml, { schema, ...options }) {\r\n\tif (options.map) {\r\n\t\tthrow new Error('`map` option was removed. Pass a `schema` option instead.')\r\n\t}\r\n\t// `parseXlsxFileContents()` function creates `options.rowIndexSourceMap` property.\r\n\t// It maps parsed data row indexes to spreadsheet row indexes.\r\n\t// That's because empty rows are ignored (discarded) when parsing using `schema`.\r\n\tconst result = parseXlsxFileContents(contents, xml, {\r\n\t\t...options,\r\n\t\tproperties: schema || options.properties\r\n\t})\r\n\tif (schema) {\r\n\t\treturn mapToObjects(result.data, schema, {\r\n\t\t\t...options,\r\n\t\t\tproperties: result.properties\r\n\t\t})\r\n\t}\r\n\treturn result\r\n}"],"mappings":";;;;;;;;;AAAA,OAAOA,qBAAqB,MAAM,4BAA4B;AAE9D,OAAOC,YAAY,MAAM,0BAA0B;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,uCAAuCA,CAACC,QAAQ,EAAEC,GAAG,EAAAC,IAAA,EAA0B;EAAA,IAAtBC,MAAM,GAAAD,IAAA,CAANC,MAAM;IAAKC,OAAO,GAAAC,wBAAA,CAAAH,IAAA,EAAAI,SAAA;EAClG,IAAIF,OAAO,CAACG,GAAG,EAAE;IAChB,MAAM,IAAIC,KAAK,CAAC,2DAA2D,CAAC;EAC7E;EACA;EACA;EACA;EACA,IAAMC,MAAM,GAAGZ,qBAAqB,CAACG,QAAQ,EAAEC,GAAG,EAAAS,aAAA,CAAAA,aAAA,KAC9CN,OAAO;IACVO,UAAU,EAAER,MAAM,IAAIC,OAAO,CAACO;EAAU,EACxC,CAAC;EACF,IAAIR,MAAM,EAAE;IACX,OAAOL,YAAY,CAACW,MAAM,CAACG,IAAI,EAAET,MAAM,EAAAO,aAAA,CAAAA,aAAA,KACnCN,OAAO;MACVO,UAAU,EAAEF,MAAM,CAACE;IAAU,EAC7B,CAAC;EACH;EACA,OAAOF,MAAM;AACd"}
@@ -1,472 +0,0 @@
1
- var _excluded = ["isColumnOriented", "ignoreEmptyRows", "rowIndexSourceMap"];
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); }
3
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
- 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."); }
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
- 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."); }
8
- 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); }
9
- 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
- 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; }
11
- 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; }
12
- 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; }
13
- 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; }
14
- 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; }
15
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
16
- 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); }
17
- import NumberType from '../../types/Number.js';
18
- import StringType from '../../types/String.js';
19
- import BooleanType from '../../types/Boolean.js';
20
- import DateType from '../../types/Date.js';
21
- var DEFAULT_OPTIONS = {
22
- schemaPropertyValueForMissingColumn: undefined,
23
- schemaPropertyValueForMissingValue: null,
24
- schemaPropertyShouldSkipRequiredValidationForMissingColumn: function schemaPropertyShouldSkipRequiredValidationForMissingColumn() {
25
- return false;
26
- },
27
- // `getEmptyObjectValue(object, { path })` applies to both the top-level object
28
- // and any of its sub-objects.
29
- getEmptyObjectValue: function getEmptyObjectValue() {
30
- return null;
31
- },
32
- getEmptyArrayValue: function getEmptyArrayValue() {
33
- return null;
34
- },
35
- isColumnOriented: false,
36
- ignoreEmptyRows: true,
37
- arrayValueSeparator: ','
38
- };
39
-
40
- /**
41
- * Converts spreadsheet-alike data structure into an array of objects.
42
- *
43
- * Parameters:
44
- *
45
- * * `data` — An array of rows, each row being an array of cells. The first row should be the list of column headers and the rest of the rows should be the data.
46
- * * `schema` — A "to JSON" convertion schema (see above).
47
- * * `options` — (optional) Schema conversion parameters of `read-excel-file`:
48
- * * `schemaPropertyValueForMissingColumn` — By default, when some of the `schema` columns are missing in the input `data`, those properties are set to `undefined` in the output objects. Pass `schemaPropertyValueForMissingColumn: null` to set such "missing column" properties to `null` in the output objects.
49
- * * `schemaPropertyValueForNullCellValue` — By default, when it encounters a `null` value in a cell in input `data`, it sets it to `undefined` in the output object. Pass `schemaPropertyValueForNullCellValue: null` to make it set such values as `null`s in output objects.
50
- * * `schemaPropertyValueForUndefinedCellValue` — By default, when it encounters an `undefined` value in a cell in input `data`, it it sets it to `undefined` in the output object. Pass `schemaPropertyValueForUndefinedCellValue: null` to make it set such values as `null`s in output objects.
51
- * * `schemaPropertyShouldSkipRequiredValidationForMissingColumn: (column: string, { object }) => boolean` — By default, it does apply `required` validation to `schema` properties for which columns are missing in the input `data`. One could pass a custom `schemaPropertyShouldSkipRequiredValidationForMissingColumn(column, { object })` to disable `required` validation for missing columns in some or all cases.
52
- * * `getEmptyObjectValue(object, { path? })` — By default, it returns `null` for "empty" objects. One could override that value using `getEmptyObjectValue(object, { path })` parameter. The value applies to both top-level object and any nested sub-objects in case of a nested schema, hence the additional (optional) `path?: string` parameter.
53
- * * `getEmptyArrayValue(array, { path })` — By default, it returns `null` for an "empty" array value. One could override that value using `getEmptyArrayValue(array, { path })` parameter.
54
- *
55
- * When parsing a property value, in case of an error, the value of that property is gonna be `undefined`.
56
- *
57
- * @param {any[][]} data - An array of rows, each row being an array of cells.
58
- * @param {object} schema
59
- * @param {object} [options]
60
- * @param {null} [options.schemaPropertyValueForMissingColumn] — By default, when some of the `schema` columns are missing in the input `data`, those properties are set to `undefined` in the output objects. Pass `schemaPropertyValueForMissingColumn: null` to set such "missing column" properties to `null` in the output objects.
61
- * @param {null} [options.schemaPropertyValueForMissingValue] — By default, when it encounters a `null` value in a cell in input `data`, it leaves the value as is. Pass a custom `schemaPropertyValueForMissingValue` to make it set such values to that value.
62
- * @param {object} [options.properties] — An optional object with optional property `epoch1904: true/false`. It is used when parsing dates.
63
- * @param {boolean} [options.schemaPropertyShouldSkipRequiredValidationForMissingColumn(column: string, { object })] — By default, it does apply `required` validation to `schema` properties for which columns are missing in the input `data`. One could pass a custom `schemaPropertyShouldSkipRequiredValidationForMissingColumn(column, { object })` to disable `required` validation for missing columns in some or all cases.
64
- * @param {function} [options.getEmptyObjectValue(object, { path })] — By default, it returns `null` for an "empty" resulting object. One could override that value using `getEmptyObjectValue(object, { path })` parameter. The value applies to both top-level object and any nested sub-objects in case of a nested schema, hence the additional `path?: string` parameter.
65
- * @param {function} [getEmptyArrayValue(array, { path })] — By default, it returns `null` for an "empty" array value. One could override that value using `getEmptyArrayValue(array, { path })` parameter.
66
- * @param {boolean} [options.isColumnOriented] — By default, the headers are assumed to be the first row in the `data`. Pass `isColumnOriented: true` if the headers are the first column in the `data`. i.e. if `data` is "transposed".
67
- * @param {string} [options.arrayValueSeparator] — When specified, string values will be split by this separator to get the array.
68
- * @param {object} [options.rowIndexSourceMap] — Custom row indexes of `data` rows. If present, will overwrite the indexes of `data` rows with the indexes from this `rowIndexSourceMap`.
69
- * @return {object[]}
70
- */
71
- export default function mapToObjects(data, schema, options) {
72
- if (options) {
73
- options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options);
74
- } else {
75
- options = DEFAULT_OPTIONS;
76
- }
77
- var _options = options,
78
- isColumnOriented = _options.isColumnOriented,
79
- ignoreEmptyRows = _options.ignoreEmptyRows,
80
- rowIndexSourceMapOriginal = _options.rowIndexSourceMap,
81
- schemaTransformOptions = _objectWithoutProperties(_options, _excluded);
82
-
83
- // `rowIndexSourceMap` could be mutated by `ignoreEmptyRows: true` option.
84
- // Create a copy of it so that the original `rowIndexSourceMap` is not affected by those changes.
85
- var rowIndexSourceMap = rowIndexSourceMapOriginal && rowIndexSourceMapOriginal.slice();
86
- validateSchema(schema);
87
- if (isColumnOriented) {
88
- data = transpose(data);
89
- }
90
- if (ignoreEmptyRows) {
91
- data = data.filter(function (row, i) {
92
- var isEmptyRow = row.every(function (cell) {
93
- return cell === null;
94
- });
95
- if (isEmptyRow) {
96
- // Adjust `rowIndexSourceMap` now that the row has been removed.
97
- if (rowIndexSourceMap) {
98
- // Remove the `rowIndexSourceMap` entry that corresponds to the removed row.
99
- rowIndexSourceMap.splice(i, 1);
100
- }
101
- return false;
102
- }
103
- return true;
104
- });
105
- }
106
- var columns = data[0];
107
- var results = [];
108
- var errors = [];
109
- for (var i = 1; i < data.length; i++) {
110
- var result = read(schema, data[i], i, undefined, columns, errors, schemaTransformOptions);
111
- results.push(result);
112
- }
113
-
114
- // Set the correct `row` number in `errors` if a custom `rowIndexSourceMap` is supplied.
115
- if (rowIndexSourceMap) {
116
- for (var _iterator = _createForOfIteratorHelperLoose(errors), _step; !(_step = _iterator()).done;) {
117
- var error = _step.value;
118
- // Convert the `row` index in `data` to the
119
- // actual `row` index in the spreadsheet.
120
- // `- 1` converts row number to row index.
121
- // `+ 1` converts row index to row number.
122
- error.row = rowIndexSourceMap[error.row - 1] + 1;
123
- }
124
- }
125
- return {
126
- rows: results,
127
- errors: errors
128
- };
129
- }
130
- function read(schema, row, rowIndex, path, columns, errors, options) {
131
- var object = {};
132
- var isEmptyObject = true;
133
- var createError = function createError(_ref) {
134
- var schemaEntry = _ref.schemaEntry,
135
- value = _ref.value,
136
- errorMessage = _ref.error,
137
- reason = _ref.reason;
138
- var error = {
139
- error: errorMessage,
140
- row: rowIndex + 1,
141
- column: schemaEntry.column,
142
- value: value
143
- };
144
- if (reason) {
145
- error.reason = reason;
146
- }
147
- // * Regular values specify a `type?` property, which is included in the `error` object.
148
- // * Nested objects specify a `schema` property, which is not included in the `error` object.
149
- if (schemaEntry.type) {
150
- error.type = schemaEntry.type;
151
- }
152
- return error;
153
- };
154
- var pendingRequiredChecks = [];
155
-
156
- // For each schema entry.
157
- var _loop = function _loop() {
158
- var key = _Object$keys[_i];
159
- var schemaEntry = schema[key];
160
- var propertyName = key;
161
- var columnTitle = schemaEntry.column;
162
-
163
- // The path of this property inside the resulting object.
164
- var propertyPath = "".concat(path || '', ".").concat(propertyName);
165
-
166
- // Read the cell value for the schema entry.
167
- var cellValue;
168
- var columnIndex = columns.indexOf(columnTitle);
169
- var isMissingColumn = columnIndex < 0;
170
- if (!isMissingColumn) {
171
- cellValue = row[columnIndex];
172
- }
173
- var value;
174
- var error;
175
- var reason;
176
-
177
- // Get property `value` from cell value.
178
- if (schemaEntry.schema) {
179
- value = read(schemaEntry.schema, row, rowIndex, propertyPath, columns, errors, options);
180
- } else {
181
- if (isMissingColumn) {
182
- if ('schemaPropertyValueForMissingColumn' in options) {
183
- value = options.schemaPropertyValueForMissingColumn;
184
- }
185
- } else if (cellValue === undefined) {
186
- // This isn't supposed to be possible. Cell values are always `null` when cells are empty.
187
- // Employ some sensible fallback behavior here.
188
- if ('schemaPropertyValueForMissingValue' in options) {
189
- value = options.schemaPropertyValueForMissingValue;
190
- }
191
- } else if (cellValue === null) {
192
- if ('schemaPropertyValueForMissingValue' in options) {
193
- value = options.schemaPropertyValueForMissingValue;
194
- }
195
- } else if (Array.isArray(schemaEntry.type)) {
196
- var array = parseArray(cellValue, options.arrayValueSeparator).map(function (_value) {
197
- if (error) {
198
- return;
199
- }
200
- var result = parseValue(_value, schemaEntry, options);
201
- if (result.error) {
202
- // In case of an error, `value` won't be returned and will just be reported
203
- // as part of an `error` object, so it's fine assigning just an element of the array.
204
- value = _value;
205
- error = result.error;
206
- reason = result.reason;
207
- }
208
- return result.value;
209
- });
210
- if (!error) {
211
- var isEmpty = array.every(isEmptyValue);
212
- value = isEmpty ? options.getEmptyArrayValue(array, {
213
- path: propertyPath
214
- }) : array;
215
- }
216
- } else {
217
- var result = parseValue(cellValue, schemaEntry, options);
218
- error = result.error;
219
- reason = result.reason;
220
- value = error ? cellValue : result.value;
221
- }
222
- }
223
-
224
- // Apply `required` validation if the value is "empty".
225
- if (!error && isEmptyValue(value)) {
226
- if (schemaEntry.required) {
227
- // Will perform this `required()` validation in the end,
228
- // when all properties of the mapped object have been mapped.
229
- pendingRequiredChecks.push({
230
- schemaEntry: schemaEntry,
231
- value: value,
232
- isMissingColumn: isMissingColumn
233
- });
234
- }
235
- }
236
- if (error) {
237
- // If there was an error then the property value in the `object` will be `undefined`,
238
- // i.e it won't add the property value to the mapped object.
239
- errors.push(createError({
240
- schemaEntry: schemaEntry,
241
- value: value,
242
- error: error,
243
- reason: reason
244
- }));
245
- } else {
246
- // Possibly unmark the mapped object as "empty".
247
- if (isEmptyObject && !isEmptyValue(value)) {
248
- isEmptyObject = false;
249
- }
250
- // Set the value in the mapped object.
251
- // Skip setting `undefined` values because they're already `undefined`
252
- // due to not having previously been set.
253
- if (value !== undefined) {
254
- object[propertyName] = value;
255
- }
256
- }
257
- };
258
- for (var _i = 0, _Object$keys = Object.keys(schema); _i < _Object$keys.length; _i++) {
259
- _loop();
260
- }
261
-
262
- // Return `null` for an "empty" mapped object.
263
- if (isEmptyObject) {
264
- return options.getEmptyObjectValue(object, {
265
- path: path
266
- });
267
- }
268
-
269
- // Perform any `required` validations.
270
- for (var _i2 = 0, _pendingRequiredCheck = pendingRequiredChecks; _i2 < _pendingRequiredCheck.length; _i2++) {
271
- var _pendingRequiredCheck2 = _pendingRequiredCheck[_i2],
272
- schemaEntry = _pendingRequiredCheck2.schemaEntry,
273
- value = _pendingRequiredCheck2.value,
274
- isMissingColumn = _pendingRequiredCheck2.isMissingColumn;
275
- // Can optionally skip `required` validation for missing columns.
276
- var skipRequiredValidation = isMissingColumn && options.schemaPropertyShouldSkipRequiredValidationForMissingColumn(schemaEntry.column, {
277
- object: object
278
- });
279
- if (!skipRequiredValidation) {
280
- var required = schemaEntry.required;
281
- var isRequired = typeof required === 'boolean' ? required : required(object);
282
- if (isRequired) {
283
- errors.push(createError({
284
- schemaEntry: schemaEntry,
285
- value: value,
286
- error: 'required'
287
- }));
288
- }
289
- }
290
- }
291
-
292
- // Return the mapped object.
293
- return object;
294
- }
295
-
296
- /**
297
- * Converts textual value to a javascript typed value.
298
- * @param {any} value
299
- * @param {object} schemaEntry
300
- * @return {{ value: any, error: string }}
301
- */
302
- export function parseValue(value, schemaEntry, options) {
303
- if (value === null) {
304
- return {
305
- value: null
306
- };
307
- }
308
- var result;
309
- if (schemaEntry.parse) {
310
- throw new Error('`schemaEntry.parse` property was renamed to `schemaEntry.type`');
311
- } else if (schemaEntry.type) {
312
- result = parseValueOfType(value,
313
- // Supports parsing array types.
314
- // See `parseArray()` function for more details.
315
- // Example `type`: String[]
316
- // Input: 'Barack Obama, "String, with, colons", Donald Trump'
317
- // Output: ['Barack Obama', 'String, with, colons', 'Donald Trump']
318
- Array.isArray(schemaEntry.type) ? schemaEntry.type[0] : schemaEntry.type, options);
319
- } else {
320
- result = {
321
- value: value
322
- };
323
- // throw new Error('Invalid schema entry: no `type` specified:\n\n' + JSON.stringify(schemaEntry, null, 2))
324
- }
325
- // If errored then return the error.
326
- if (result.error) {
327
- return result;
328
- }
329
- if (result.value !== null) {
330
- if (schemaEntry.oneOf && schemaEntry.oneOf.indexOf(result.value) < 0) {
331
- return {
332
- error: 'invalid',
333
- reason: 'unknown'
334
- };
335
- }
336
- if (schemaEntry.validate) {
337
- try {
338
- schemaEntry.validate(result.value);
339
- } catch (error) {
340
- return {
341
- error: error.message
342
- };
343
- }
344
- }
345
- }
346
- return result;
347
- }
348
-
349
- /**
350
- * Converts textual value to a custom value using supplied `.parse()`.
351
- * @param {any} value
352
- * @param {function} parse
353
- * @return {{ value: any, error: string }}
354
- */
355
- function parseCustomValue(value, parse) {
356
- try {
357
- var parsedValue = parse(value);
358
- if (parsedValue === undefined) {
359
- return {
360
- value: null
361
- };
362
- }
363
- return {
364
- value: parsedValue
365
- };
366
- } catch (error) {
367
- var result = {
368
- error: error.message
369
- };
370
- if (error.reason) {
371
- result.reason = error.reason;
372
- }
373
- return result;
374
- }
375
- }
376
-
377
- /**
378
- * Converts textual value to a javascript typed value.
379
- * @param {any} value
380
- * @param {} type
381
- * @return {{ value: (string|number|Date|boolean), error: string, reason?: string }}
382
- */
383
- function parseValueOfType(value, type, options) {
384
- switch (type) {
385
- case String:
386
- return parseCustomValue(value, StringType);
387
- case Number:
388
- return parseCustomValue(value, NumberType);
389
- case Date:
390
- return parseCustomValue(value, function (value) {
391
- return DateType(value, {
392
- properties: options.properties
393
- });
394
- });
395
- case Boolean:
396
- return parseCustomValue(value, BooleanType);
397
- default:
398
- if (typeof type === 'function') {
399
- return parseCustomValue(value, type);
400
- }
401
- throw new Error("Unsupported schema type: ".concat(type && type.name || type));
402
- }
403
- }
404
- export function getBlock(string, endCharacter, startIndex) {
405
- var i = 0;
406
- var substring = '';
407
- var character;
408
- while (startIndex + i < string.length) {
409
- var _character = string[startIndex + i];
410
- if (_character === endCharacter) {
411
- return [substring, i];
412
- } else if (_character === '"') {
413
- var block = getBlock(string, '"', startIndex + i + 1);
414
- substring += block[0];
415
- i += '"'.length + block[1] + '"'.length;
416
- } else {
417
- substring += _character;
418
- i++;
419
- }
420
- }
421
- return [substring, i];
422
- }
423
-
424
- /**
425
- * Parses a string of comma-separated substrings into an array of substrings.
426
- * (the `export` is just for tests)
427
- * @param {string} string — A string of comma-separated substrings.
428
- * @return {string[]} An array of substrings.
429
- */
430
- export function parseArray(string, arrayValueSeparator) {
431
- var blocks = [];
432
- var index = 0;
433
- while (index < string.length) {
434
- var _getBlock = getBlock(string, arrayValueSeparator, index),
435
- _getBlock2 = _slicedToArray(_getBlock, 2),
436
- substring = _getBlock2[0],
437
- length = _getBlock2[1];
438
- index += length + arrayValueSeparator.length;
439
- blocks.push(substring.trim());
440
- }
441
- return blocks;
442
- }
443
-
444
- // Transpose a 2D array.
445
- // https://stackoverflow.com/questions/17428587/transposing-a-2d-array-in-javascript
446
- var transpose = function transpose(array) {
447
- return array[0].map(function (_, i) {
448
- return array.map(function (row) {
449
- return row[i];
450
- });
451
- });
452
- };
453
- function validateSchema(schema) {
454
- for (var _i3 = 0, _Object$keys2 = Object.keys(schema); _i3 < _Object$keys2.length; _i3++) {
455
- var key = _Object$keys2[_i3];
456
- var schemaEntry = schema[key];
457
- // Validate that the `schema` is not using a deprecated `type: nestedSchema` format.
458
- if (_typeof(schemaEntry.type) === 'object' && !Array.isArray(schemaEntry.type)) {
459
- throw new Error('When defining a nested schema, use a `schema` property instead of a `type` property');
460
- }
461
- // Validate that every property has a source `column` title specified for it.
462
- if (!schemaEntry.schema) {
463
- if (!schemaEntry.column) {
464
- throw new Error("\"column\" not defined for schema entry \"".concat(key, "\"."));
465
- }
466
- }
467
- }
468
- }
469
- function isEmptyValue(value) {
470
- return value === undefined || value === null;
471
- }
472
- //# sourceMappingURL=mapToObjects.js.map