read-excel-file 5.7.1 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +45 -19
- package/bundle/read-excel-file.min.js +1 -1
- package/bundle/read-excel-file.min.js.map +1 -1
- package/commonjs/read/coordinates.js +7 -10
- package/commonjs/read/coordinates.js.map +1 -1
- package/commonjs/read/dropEmptyColumns.js +6 -18
- package/commonjs/read/dropEmptyColumns.js.map +1 -1
- package/commonjs/read/dropEmptyColumns.test.js.map +1 -1
- package/commonjs/read/dropEmptyRows.js +11 -23
- package/commonjs/read/dropEmptyRows.js.map +1 -1
- package/commonjs/read/dropEmptyRows.test.js.map +1 -1
- package/commonjs/read/getData.js +31 -43
- package/commonjs/read/getData.js.map +1 -1
- package/commonjs/read/isDateTimestamp.js +51 -40
- package/commonjs/read/isDateTimestamp.js.map +1 -1
- package/commonjs/read/parseCell.js +3 -10
- package/commonjs/read/parseCell.js.map +1 -1
- package/commonjs/read/parseCellValue.js +28 -59
- package/commonjs/read/parseCellValue.js.map +1 -1
- package/commonjs/read/parseCells.js +3 -7
- package/commonjs/read/parseCells.js.map +1 -1
- package/commonjs/read/parseDate.js +5 -5
- package/commonjs/read/parseDate.js.map +1 -1
- package/commonjs/read/parseDate.test.js.map +1 -1
- package/commonjs/read/parseDimensions.js +6 -18
- package/commonjs/read/parseDimensions.js.map +1 -1
- package/commonjs/read/parseFilePaths.js +4 -11
- package/commonjs/read/parseFilePaths.js.map +1 -1
- package/commonjs/read/parseProperties.js +6 -8
- package/commonjs/read/parseProperties.js.map +1 -1
- package/commonjs/read/parseSharedStrings.js +0 -3
- package/commonjs/read/parseSharedStrings.js.map +1 -1
- package/commonjs/read/parseSheet.js +3 -7
- package/commonjs/read/parseSheet.js.map +1 -1
- package/commonjs/read/parseStyles.js +13 -21
- package/commonjs/read/parseStyles.js.map +1 -1
- package/commonjs/read/readSheetNamesBrowser.js +0 -3
- package/commonjs/read/readSheetNamesBrowser.js.map +1 -1
- package/commonjs/read/readSheetNamesNode.js +0 -3
- package/commonjs/read/readSheetNamesNode.js.map +1 -1
- package/commonjs/read/readSheetNamesNode.test.js.map +1 -1
- package/commonjs/read/readSheetNamesWebWorker.js +0 -3
- package/commonjs/read/readSheetNamesWebWorker.js.map +1 -1
- package/commonjs/read/readXlsx.js +34 -42
- package/commonjs/read/readXlsx.js.map +1 -1
- package/commonjs/read/readXlsxFileBrowser.js +0 -5
- package/commonjs/read/readXlsxFileBrowser.js.map +1 -1
- package/commonjs/read/readXlsxFileContents.js +12 -22
- package/commonjs/read/readXlsxFileContents.js.map +1 -1
- package/commonjs/read/readXlsxFileNode.js +0 -5
- package/commonjs/read/readXlsxFileNode.js.map +1 -1
- package/commonjs/read/readXlsxFileNode.test.js.map +1 -1
- package/commonjs/read/readXlsxFileWebWorker.js +0 -5
- package/commonjs/read/readXlsxFileWebWorker.js.map +1 -1
- package/commonjs/read/schema/convertMapToSchema.js +1 -8
- package/commonjs/read/schema/convertMapToSchema.js.map +1 -1
- package/commonjs/read/schema/convertMapToSchema.test.js.map +1 -1
- package/commonjs/read/schema/convertToJson.js +143 -142
- package/commonjs/read/schema/convertToJson.js.map +1 -1
- package/commonjs/read/schema/convertToJson.legacy.js +60 -0
- package/commonjs/read/schema/convertToJson.legacy.js.map +1 -0
- package/commonjs/read/schema/convertToJson.legacy.test.js.map +1 -0
- package/commonjs/read/schema/convertToJson.spreadsheet.js +25 -0
- package/commonjs/read/schema/convertToJson.spreadsheet.js.map +1 -0
- package/commonjs/read/schema/convertToJson.spreadsheet.test.js.map +1 -0
- package/commonjs/read/schema/convertToJson.test.js.map +1 -1
- package/commonjs/read/unpackXlsxFileBrowser.js +3 -9
- package/commonjs/read/unpackXlsxFileBrowser.js.map +1 -1
- package/commonjs/read/unpackXlsxFileNode.js +9 -15
- package/commonjs/read/unpackXlsxFileNode.js.map +1 -1
- package/commonjs/types/Boolean.js +0 -4
- package/commonjs/types/Boolean.js.map +1 -1
- package/commonjs/types/Date.js +0 -12
- package/commonjs/types/Date.js.map +1 -1
- package/commonjs/types/Email.js +0 -7
- package/commonjs/types/Email.js.map +1 -1
- package/commonjs/types/Email.test.js.map +1 -1
- package/commonjs/types/Integer.js +0 -7
- package/commonjs/types/Integer.js.map +1 -1
- package/commonjs/types/Integer.test.js.map +1 -1
- package/commonjs/types/InvalidError.js +8 -28
- package/commonjs/types/InvalidError.js.map +1 -1
- package/commonjs/types/Number.js +2 -10
- package/commonjs/types/Number.js.map +1 -1
- package/commonjs/types/String.js +4 -11
- package/commonjs/types/String.js.map +1 -1
- package/commonjs/types/URL.js +5 -8
- package/commonjs/types/URL.js.map +1 -1
- package/commonjs/types/URL.test.js.map +1 -1
- package/commonjs/xml/dom.js +6 -25
- package/commonjs/xml/dom.js.map +1 -1
- package/commonjs/xml/xlsx.js +1 -24
- package/commonjs/xml/xlsx.js.map +1 -1
- package/commonjs/xml/xml.js +1 -4
- package/commonjs/xml/xml.js.map +1 -1
- package/commonjs/xml/xmlBrowser.js +1 -2
- package/commonjs/xml/xmlBrowser.js.map +1 -1
- package/commonjs/xml/xpath/xlsx-xpath.js +3 -16
- package/commonjs/xml/xpath/xlsx-xpath.js.map +1 -1
- package/commonjs/xml/xpath/xpathBrowser.js +3 -5
- package/commonjs/xml/xpath/xpathBrowser.js.map +1 -1
- package/commonjs/xml/xpath/xpathNode.js +1 -5
- package/commonjs/xml/xpath/xpathNode.js.map +1 -1
- package/map/index.cjs +2 -0
- package/map/index.cjs.js +7 -0
- package/map/index.d.ts +11 -0
- package/map/index.js +1 -0
- package/map/package.json +17 -0
- package/modules/read/coordinates.js +7 -8
- package/modules/read/coordinates.js.map +1 -1
- package/modules/read/dropEmptyColumns.js +6 -17
- package/modules/read/dropEmptyColumns.js.map +1 -1
- package/modules/read/dropEmptyColumns.test.js.map +1 -1
- package/modules/read/dropEmptyRows.js +11 -22
- package/modules/read/dropEmptyRows.js.map +1 -1
- package/modules/read/dropEmptyRows.test.js.map +1 -1
- package/modules/read/getData.js +31 -39
- package/modules/read/getData.js.map +1 -1
- package/modules/read/isDateTimestamp.js +52 -39
- package/modules/read/isDateTimestamp.js.map +1 -1
- package/modules/read/parseCell.js +6 -6
- package/modules/read/parseCell.js.map +1 -1
- package/modules/read/parseCellValue.js +30 -55
- package/modules/read/parseCellValue.js.map +1 -1
- package/modules/read/parseCells.js +3 -3
- package/modules/read/parseCells.js.map +1 -1
- package/modules/read/parseDate.js +5 -4
- package/modules/read/parseDate.js.map +1 -1
- package/modules/read/parseDate.test.js.map +1 -1
- package/modules/read/parseDimensions.js +9 -17
- package/modules/read/parseDimensions.js.map +1 -1
- package/modules/read/parseFilePaths.js +5 -10
- package/modules/read/parseFilePaths.js.map +1 -1
- package/modules/read/parseProperties.js +8 -7
- package/modules/read/parseProperties.js.map +1 -1
- package/modules/read/parseSharedStrings.js +0 -1
- package/modules/read/parseSharedStrings.js.map +1 -1
- package/modules/read/parseSheet.js +3 -2
- package/modules/read/parseSheet.js.map +1 -1
- package/modules/read/parseStyles.js +16 -21
- package/modules/read/parseStyles.js.map +1 -1
- package/modules/read/readSheetNamesBrowser.js +1 -1
- package/modules/read/readSheetNamesBrowser.js.map +1 -1
- package/modules/read/readSheetNamesNode.js +1 -1
- package/modules/read/readSheetNamesNode.js.map +1 -1
- package/modules/read/readSheetNamesNode.test.js.map +1 -1
- package/modules/read/readSheetNamesWebWorker.js +1 -1
- package/modules/read/readSheetNamesWebWorker.js.map +1 -1
- package/modules/read/readXlsx.js +37 -35
- package/modules/read/readXlsx.js.map +1 -1
- package/modules/read/readXlsxFileBrowser.js +1 -1
- package/modules/read/readXlsxFileBrowser.js.map +1 -1
- package/modules/read/readXlsxFileContents.js +12 -17
- package/modules/read/readXlsxFileContents.js.map +1 -1
- package/modules/read/readXlsxFileNode.js +1 -1
- package/modules/read/readXlsxFileNode.js.map +1 -1
- package/modules/read/readXlsxFileNode.test.js.map +1 -1
- package/modules/read/readXlsxFileWebWorker.js +1 -1
- package/modules/read/readXlsxFileWebWorker.js.map +1 -1
- package/modules/read/schema/convertMapToSchema.js +1 -7
- package/modules/read/schema/convertMapToSchema.js.map +1 -1
- package/modules/read/schema/convertMapToSchema.test.js.map +1 -1
- package/modules/read/schema/convertToJson.js +143 -133
- package/modules/read/schema/convertToJson.js.map +1 -1
- package/modules/read/schema/convertToJson.legacy.js +53 -0
- package/modules/read/schema/convertToJson.legacy.js.map +1 -0
- package/modules/read/schema/convertToJson.legacy.test.js.map +1 -0
- package/modules/read/schema/convertToJson.spreadsheet.js +19 -0
- package/modules/read/schema/convertToJson.spreadsheet.js.map +1 -0
- package/modules/read/schema/convertToJson.spreadsheet.test.js.map +1 -0
- package/modules/read/schema/convertToJson.test.js.map +1 -1
- package/modules/read/unpackXlsxFileBrowser.js +4 -7
- package/modules/read/unpackXlsxFileBrowser.js.map +1 -1
- package/modules/read/unpackXlsxFileNode.js +9 -7
- package/modules/read/unpackXlsxFileNode.js.map +1 -1
- package/modules/types/Boolean.js +0 -1
- package/modules/types/Boolean.js.map +1 -1
- package/modules/types/Date.js +0 -8
- package/modules/types/Date.js.map +1 -1
- package/modules/types/Email.js +0 -2
- package/modules/types/Email.js.map +1 -1
- package/modules/types/Email.test.js.map +1 -1
- package/modules/types/Integer.js +0 -2
- package/modules/types/Integer.js.map +1 -1
- package/modules/types/Integer.test.js.map +1 -1
- package/modules/types/InvalidError.js +7 -25
- package/modules/types/InvalidError.js.map +1 -1
- package/modules/types/Number.js +2 -7
- package/modules/types/Number.js.map +1 -1
- package/modules/types/String.js +4 -8
- package/modules/types/String.js.map +1 -1
- package/modules/types/URL.js +5 -4
- package/modules/types/URL.js.map +1 -1
- package/modules/types/URL.test.js.map +1 -1
- package/modules/xml/dom.js +6 -18
- package/modules/xml/dom.js.map +1 -1
- package/modules/xml/xlsx.js +4 -13
- package/modules/xml/xlsx.js.map +1 -1
- package/modules/xml/xml.js.map +1 -1
- package/modules/xml/xmlBrowser.js.map +1 -1
- package/modules/xml/xpath/xlsx-xpath.js +2 -1
- package/modules/xml/xpath/xlsx-xpath.js.map +1 -1
- package/modules/xml/xpath/xpathBrowser.js +3 -4
- package/modules/xml/xpath/xpathBrowser.js.map +1 -1
- package/modules/xml/xpath/xpathNode.js +1 -0
- package/modules/xml/xpath/xpathNode.js.map +1 -1
- package/package.json +6 -1
- package/schema/index.cjs +2 -2
- package/schema/index.cjs.js +2 -2
- package/schema/index.d.ts +7 -2
- package/schema/index.js +1 -1
- package/types.d.ts +25 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isDateTimestamp.js","names":["isDateTimestamp","styleId","styles","options","style","Error","numberFormat","BUILT_IN_DATE_NUMBER_FORMAT_IDS","indexOf","Number","id","dateFormat","template","smartDateParser","isDateTemplate","DATE_FORMAT_WEIRD_PREFIX","DATE_FORMAT_WEIRD_POSTFIX","toLowerCase","replace","tokens","split","token","DATE_TEMPLATE_TOKENS"],"sources":["../../source/read/isDateTimestamp.js"],"sourcesContent":["// XLSX does have \"d\" type for dates, but it's not commonly used.\r\n// Instead, it prefers using \"n\" type for storing dates as timestamps.\r\n//\r\n// Whether a numeric value is a number or a date timestamp, it sometimes could be\r\n// detected by looking at the value \"format\" and seeing if it's a date-specific one.\r\n// https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777\r\n//\r\n// The list of generic numeric value \"formats\":\r\n// https://xlsxwriter.readthedocs.io/format.html#format-set-num-format\r\n//\r\nexport default function isDateTimestamp(styleId, styles, options) {\r\n if (styleId) {\r\n const style = styles[styleId]\r\n if (!style) {\r\n throw new Error(`Cell style not found: ${styleId}`)\r\n }\r\n if (!style.numberFormat) {\r\n return false\r\n }\r\n if (\r\n // Whether it's a \"number format\" that's conventionally used for storing date timestamps.\r\n BUILT_IN_DATE_NUMBER_FORMAT_IDS.indexOf(Number(style.numberFormat.id)) >= 0 ||\r\n // Whether it's a \"number format\" that uses a \"formatting template\"\r\n // that the developer is certain is a date formatting template.\r\n (options.dateFormat && style.numberFormat.template === options.dateFormat) ||\r\n // Whether the \"smart formatting template\" feature is not disabled\r\n // and it has detected that it's a date formatting template by looking at it.\r\n (options.smartDateParser !== false && style.numberFormat.template && isDateTemplate(style.numberFormat.template))\r\n ) {\r\n return true\r\n }\r\n }\r\n}\r\n\r\n// https://hexdocs.pm/xlsxir/number_styles.html\r\nconst BUILT_IN_DATE_NUMBER_FORMAT_IDS = [14,15,16,17,18,19,20,21,22,27,30,36,45,46,47,50,57]\r\n\r\n// On some date formats, there's an \"[$-414]\" prefix.\r\n// I don't have any idea what that is.\r\n//\r\n// https://stackoverflow.com/questions/4730152/what-indicates-an-office-open-xml-cell-contains-a-date-time-value\r\n//\r\n// Examples:\r\n//\r\n// * 27 (built-in format) \"[$-404]e/m/d\"\r\n// * 164 (custom format) \"[$-414]mmmm\\ yyyy;@\"\r\n//\r\nconst DATE_FORMAT_WEIRD_PREFIX = /^\\[\\$-414\\]/\r\n\r\n// On some date formats, there's an \";@\" postfix.\r\n// I don't have any idea what that is.\r\n// Examples:\r\n//\r\n// * 164 (custom format) \"m/d/yyyy;@\"\r\n// * 164 (custom format) \"[$-414]mmmm\\ yyyy;@\"\r\n//\r\nconst DATE_FORMAT_WEIRD_POSTFIX = /;@$/\r\n\r\nfunction isDateTemplate(template) {\r\n // Date format tokens could be in upper case or in lower case.\r\n // There seems to be no single standard.\r\n // So lowercase the template first.\r\n template = template.toLowerCase()\r\n\r\n // On some date formats, there's an \"[$-414]\" prefix.\r\n // I don't have any idea what that is. Trim it.\r\n template = template.replace(DATE_FORMAT_WEIRD_PREFIX, '')\r\n\r\n // On some date formats, there's an \";@\" postfix.\r\n // I don't have any idea what that is. Trim it.\r\n template = template.replace(DATE_FORMAT_WEIRD_POSTFIX, '')\r\n\r\n const tokens = template.split(/\\W+/)\r\n for (const token of tokens) {\r\n if (DATE_TEMPLATE_TOKENS.indexOf(token) < 0) {\r\n return false\r\n }\r\n }\r\n return true\r\n}\r\n\r\n// These tokens could be in upper case or in lower case.\r\n// There seems to be no single standard, so using lower case.\r\nconst DATE_TEMPLATE_TOKENS = [\r\n // Seconds (min two digits). Example: \"05\".\r\n 'ss',\r\n // Minutes (min two digits). Example: \"05\". Could also be \"Months\". Weird.\r\n 'mm',\r\n // Hours. Example: \"1\".\r\n 'h',\r\n // Hours (min two digits). Example: \"01\".\r\n 'hh',\r\n // \"AM\" part of \"AM/PM\". Lowercased just in case.\r\n 'am',\r\n // \"PM\" part of \"AM/PM\". Lowercased just in case.\r\n 'pm',\r\n // Day. Example: \"1\"\r\n 'd',\r\n // Day (min two digits). Example: \"01\"\r\n 'dd',\r\n // Month (numeric). Example: \"1\".\r\n 'm',\r\n // Month (numeric, min two digits). Example: \"01\". Could also be \"Minutes\". Weird.\r\n 'mm',\r\n // Month (shortened month name). Example: \"Jan\".\r\n 'mmm',\r\n // Month (full month name). Example: \"January\".\r\n 'mmmm',\r\n // Two-digit year. Example: \"20\".\r\n 'yy',\r\n // Full year. Example: \"2020\".\r\n 'yyyy',\r\n\r\n // I don't have any idea what \"e\" means.\r\n // It's used in \"built-in\" XLSX formats:\r\n // * 27 '[$-404]e/m/d';\r\n // * 36 '[$-404]e/m/d';\r\n // * 50 '[$-404]e/m/d';\r\n // * 57 '[$-404]e/m/d';\r\n 'e'\r\n];"],"mappings":"
|
|
1
|
+
{"version":3,"file":"isDateTimestamp.js","names":["isDateTimestamp","styleId","styles","options","style","Error","concat","numberFormat","BUILT_IN_DATE_NUMBER_FORMAT_IDS","indexOf","Number","id","dateFormat","template","smartDateParser","isDateTemplate","DATE_FORMAT_WEIRD_PREFIX","DATE_FORMAT_WEIRD_POSTFIX","toLowerCase","replace","tokens","split","_iterator","_createForOfIteratorHelperLoose","_step","done","token","value","DATE_TEMPLATE_TOKENS"],"sources":["../../source/read/isDateTimestamp.js"],"sourcesContent":["// XLSX does have \"d\" type for dates, but it's not commonly used.\r\n// Instead, it prefers using \"n\" type for storing dates as timestamps.\r\n//\r\n// Whether a numeric value is a number or a date timestamp, it sometimes could be\r\n// detected by looking at the value \"format\" and seeing if it's a date-specific one.\r\n// https://github.com/catamphetamine/read-excel-file/issues/3#issuecomment-395770777\r\n//\r\n// The list of generic numeric value \"formats\":\r\n// https://xlsxwriter.readthedocs.io/format.html#format-set-num-format\r\n//\r\nexport default function isDateTimestamp(styleId, styles, options) {\r\n if (styleId) {\r\n const style = styles[styleId]\r\n if (!style) {\r\n throw new Error(`Cell style not found: ${styleId}`)\r\n }\r\n if (!style.numberFormat) {\r\n return false\r\n }\r\n if (\r\n // Whether it's a \"number format\" that's conventionally used for storing date timestamps.\r\n BUILT_IN_DATE_NUMBER_FORMAT_IDS.indexOf(Number(style.numberFormat.id)) >= 0 ||\r\n // Whether it's a \"number format\" that uses a \"formatting template\"\r\n // that the developer is certain is a date formatting template.\r\n (options.dateFormat && style.numberFormat.template === options.dateFormat) ||\r\n // Whether the \"smart formatting template\" feature is not disabled\r\n // and it has detected that it's a date formatting template by looking at it.\r\n (options.smartDateParser !== false && style.numberFormat.template && isDateTemplate(style.numberFormat.template))\r\n ) {\r\n return true\r\n }\r\n }\r\n}\r\n\r\n// https://hexdocs.pm/xlsxir/number_styles.html\r\nconst BUILT_IN_DATE_NUMBER_FORMAT_IDS = [14,15,16,17,18,19,20,21,22,27,30,36,45,46,47,50,57]\r\n\r\n// On some date formats, there's an \"[$-414]\" prefix.\r\n// I don't have any idea what that is.\r\n//\r\n// https://stackoverflow.com/questions/4730152/what-indicates-an-office-open-xml-cell-contains-a-date-time-value\r\n//\r\n// Examples:\r\n//\r\n// * 27 (built-in format) \"[$-404]e/m/d\"\r\n// * 164 (custom format) \"[$-414]mmmm\\ yyyy;@\"\r\n//\r\nconst DATE_FORMAT_WEIRD_PREFIX = /^\\[\\$-414\\]/\r\n\r\n// On some date formats, there's an \";@\" postfix.\r\n// I don't have any idea what that is.\r\n// Examples:\r\n//\r\n// * 164 (custom format) \"m/d/yyyy;@\"\r\n// * 164 (custom format) \"[$-414]mmmm\\ yyyy;@\"\r\n//\r\nconst DATE_FORMAT_WEIRD_POSTFIX = /;@$/\r\n\r\nfunction isDateTemplate(template) {\r\n // Date format tokens could be in upper case or in lower case.\r\n // There seems to be no single standard.\r\n // So lowercase the template first.\r\n template = template.toLowerCase()\r\n\r\n // On some date formats, there's an \"[$-414]\" prefix.\r\n // I don't have any idea what that is. Trim it.\r\n template = template.replace(DATE_FORMAT_WEIRD_PREFIX, '')\r\n\r\n // On some date formats, there's an \";@\" postfix.\r\n // I don't have any idea what that is. Trim it.\r\n template = template.replace(DATE_FORMAT_WEIRD_POSTFIX, '')\r\n\r\n const tokens = template.split(/\\W+/)\r\n for (const token of tokens) {\r\n if (DATE_TEMPLATE_TOKENS.indexOf(token) < 0) {\r\n return false\r\n }\r\n }\r\n return true\r\n}\r\n\r\n// These tokens could be in upper case or in lower case.\r\n// There seems to be no single standard, so using lower case.\r\nconst DATE_TEMPLATE_TOKENS = [\r\n // Seconds (min two digits). Example: \"05\".\r\n 'ss',\r\n // Minutes (min two digits). Example: \"05\". Could also be \"Months\". Weird.\r\n 'mm',\r\n // Hours. Example: \"1\".\r\n 'h',\r\n // Hours (min two digits). Example: \"01\".\r\n 'hh',\r\n // \"AM\" part of \"AM/PM\". Lowercased just in case.\r\n 'am',\r\n // \"PM\" part of \"AM/PM\". Lowercased just in case.\r\n 'pm',\r\n // Day. Example: \"1\"\r\n 'd',\r\n // Day (min two digits). Example: \"01\"\r\n 'dd',\r\n // Month (numeric). Example: \"1\".\r\n 'm',\r\n // Month (numeric, min two digits). Example: \"01\". Could also be \"Minutes\". Weird.\r\n 'mm',\r\n // Month (shortened month name). Example: \"Jan\".\r\n 'mmm',\r\n // Month (full month name). Example: \"January\".\r\n 'mmmm',\r\n // Two-digit year. Example: \"20\".\r\n 'yy',\r\n // Full year. Example: \"2020\".\r\n 'yyyy',\r\n\r\n // I don't have any idea what \"e\" means.\r\n // It's used in \"built-in\" XLSX formats:\r\n // * 27 '[$-404]e/m/d';\r\n // * 36 '[$-404]e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EvC,SAASF,cAAcA,CAACF,QAAQ,EAAE;EAChC;EACA;EACA;EACAA,QAAQ,GAAGA,QAAQ,CAACK,WAAW,CAAC,CAAC;;EAEjC;EACA;EACAL,QAAQ,GAAGA,QAAQ,CAACM,OAAO,CAACH,wBAAwB,EAAE,EAAE,CAAC;;EAEzD;EACA;EACAH,QAAQ,GAAGA,QAAQ,CAACM,OAAO,CAACF,yBAAyB,EAAE,EAAE,CAAC;EAE1D,IAAMG,MAAM,GAAGP,QAAQ,CAACQ,KAAK,CAAC,KAAK,CAAC;EACpC,SAAAC,SAAA,GAAAC,+BAAA,CAAoBH,MAAM,GAAAI,KAAA,IAAAA,KAAA,GAAAF,SAAA,IAAAG,IAAA,GAAE;IAAA,IAAjBC,KAAK,GAAAF,KAAA,CAAAG,KAAA;IACd,IAAIC,oBAAoB,CAACnB,OAAO,CAACiB,KAAK,CAAC,GAAG,CAAC,EAAE;MAC3C,OAAO,KAAK;IACd;EACF;EACA,OAAO,IAAI;AACb;;AAEA;AACA;AACA,IAAME,oBAAoB,GAAG;AAC3B;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA,GAAG;AACH;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA,IAAI;AACJ;AACA,GAAG;AACH;AACA,IAAI;AACJ;AACA,GAAG;AACH;AACA,IAAI;AACJ;AACA,KAAK;AACL;AACA,MAAM;AACN;AACA,IAAI;AACJ;AACA,MAAM;AAEN;AACA;AACA;AACA;AACA;AACA;AACA,GAAG,CACJ"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import parseCellValue from './parseCellValue.js';
|
|
2
2
|
import { parseCellCoordinates } from './coordinates.js';
|
|
3
3
|
import { getCellValue, getCellInlineStringValue } from '../xml/xlsx.js';
|
|
4
|
-
import { getOuterXml } from '../xml/dom.js';
|
|
4
|
+
import { getOuterXml } from '../xml/dom.js';
|
|
5
|
+
|
|
6
|
+
// Example of a `<c/>`ell element:
|
|
5
7
|
//
|
|
6
8
|
// <c>
|
|
7
9
|
// <f>string</f> — formula.
|
|
@@ -26,20 +28,18 @@ import { getOuterXml } from '../xml/dom.js'; // Example of a `<c/>`ell element:
|
|
|
26
28
|
// </extLst>
|
|
27
29
|
// </c>
|
|
28
30
|
//
|
|
29
|
-
|
|
30
31
|
export default function parseCell(node, sheet, xml, values, styles, properties, options) {
|
|
31
32
|
var coords = parseCellCoordinates(node.getAttribute('r'));
|
|
32
|
-
var valueElement = getCellValue(sheet, node);
|
|
33
|
+
var valueElement = getCellValue(sheet, node);
|
|
34
|
+
|
|
35
|
+
// For `xpath`, `value` can be `undefined` while for native `DOMParser` it's `null`.
|
|
33
36
|
// So using `value && ...` instead of `if (value !== undefined) { ... }` here
|
|
34
37
|
// for uniform compatibility with both `xpath` and native `DOMParser`.
|
|
35
|
-
|
|
36
38
|
var value = valueElement && valueElement.textContent;
|
|
37
39
|
var type;
|
|
38
|
-
|
|
39
40
|
if (node.hasAttribute('t')) {
|
|
40
41
|
type = node.getAttribute('t');
|
|
41
42
|
}
|
|
42
|
-
|
|
43
43
|
return {
|
|
44
44
|
row: coords[0],
|
|
45
45
|
column: coords[1],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseCell.js","names":["parseCellValue","parseCellCoordinates","getCellValue","getCellInlineStringValue","getOuterXml","parseCell","node","sheet","xml","values","styles","properties","options","coords","getAttribute","valueElement","value","textContent","type","hasAttribute","row","column","getInlineStringValue","getInlineStringXml","getStyleId"],"sources":["../../source/read/parseCell.js"],"sourcesContent":["import parseCellValue from './parseCellValue.js'\r\n\r\nimport {\r\n parseCellCoordinates\r\n} from './coordinates.js'\r\n\r\nimport {\r\n getCellValue,\r\n getCellInlineStringValue\r\n} from '../xml/xlsx.js'\r\n\r\nimport {\r\n getOuterXml\r\n} from '../xml/dom.js'\r\n\r\n// Example of a `<c/>`ell element:\r\n//\r\n// <c>\r\n// <f>string</f> — formula.\r\n// <v>string</v> — formula pre-computed value.\r\n// <is>\r\n// <t>string</t> — an `inlineStr` string (rather than a \"common string\" from a dictionary).\r\n// <r>\r\n// <rPr>\r\n// ...\r\n// </rPr>\r\n// <t>string</t>\r\n// </r>\r\n// <rPh sb=\"1\" eb=\"1\">\r\n// <t>string</t>\r\n// </rPh>\r\n// <phoneticPr fontId=\"1\"/>\r\n// </is>\r\n// <extLst>\r\n// <ext>\r\n// <!--any element-->\r\n// </ext>\r\n// </extLst>\r\n// </c>\r\n//\r\nexport default function parseCell(node, sheet, xml, values, styles, properties, options) {\r\n const coords = parseCellCoordinates(node.getAttribute('r'))\r\n\r\n const valueElement = getCellValue(sheet, node)\r\n\r\n // For `xpath`, `value` can be `undefined` while for native `DOMParser` it's `null`.\r\n // So using `value && ...` instead of `if (value !== undefined) { ... }` here\r\n // for uniform compatibility with both `xpath` and native `DOMParser`.\r\n let value = valueElement && valueElement.textContent\r\n\r\n let type\r\n if (node.hasAttribute('t')) {\r\n type = node.getAttribute('t')\r\n }\r\n\r\n return {\r\n row: coords[0],\r\n column: coords[1],\r\n value: parseCellValue(value, type, {\r\n getInlineStringValue: () => getCellInlineStringValue(sheet, node),\r\n getInlineStringXml: () => getOuterXml(node),\r\n getStyleId: () => node.getAttribute('s'),\r\n styles,\r\n values,\r\n properties,\r\n options\r\n })\r\n }\r\n}"],"mappings":"AAAA,OAAOA,
|
|
1
|
+
{"version":3,"file":"parseCell.js","names":["parseCellValue","parseCellCoordinates","getCellValue","getCellInlineStringValue","getOuterXml","parseCell","node","sheet","xml","values","styles","properties","options","coords","getAttribute","valueElement","value","textContent","type","hasAttribute","row","column","getInlineStringValue","getInlineStringXml","getStyleId"],"sources":["../../source/read/parseCell.js"],"sourcesContent":["import parseCellValue from './parseCellValue.js'\r\n\r\nimport {\r\n parseCellCoordinates\r\n} from './coordinates.js'\r\n\r\nimport {\r\n getCellValue,\r\n getCellInlineStringValue\r\n} from '../xml/xlsx.js'\r\n\r\nimport {\r\n getOuterXml\r\n} from '../xml/dom.js'\r\n\r\n// Example of a `<c/>`ell element:\r\n//\r\n// <c>\r\n// <f>string</f> — formula.\r\n// <v>string</v> — formula pre-computed value.\r\n// <is>\r\n// <t>string</t> — an `inlineStr` string (rather than a \"common string\" from a dictionary).\r\n// <r>\r\n// <rPr>\r\n// ...\r\n// </rPr>\r\n// <t>string</t>\r\n// </r>\r\n// <rPh sb=\"1\" eb=\"1\">\r\n// <t>string</t>\r\n// </rPh>\r\n// <phoneticPr fontId=\"1\"/>\r\n// </is>\r\n// <extLst>\r\n// <ext>\r\n// <!--any element-->\r\n// </ext>\r\n// </extLst>\r\n// </c>\r\n//\r\nexport default function parseCell(node, sheet, xml, values, styles, properties, options) {\r\n const coords = parseCellCoordinates(node.getAttribute('r'))\r\n\r\n const valueElement = getCellValue(sheet, node)\r\n\r\n // For `xpath`, `value` can be `undefined` while for native `DOMParser` it's `null`.\r\n // So using `value && ...` instead of `if (value !== undefined) { ... }` here\r\n // for uniform compatibility with both `xpath` and native `DOMParser`.\r\n let value = valueElement && valueElement.textContent\r\n\r\n let type\r\n if (node.hasAttribute('t')) {\r\n type = node.getAttribute('t')\r\n }\r\n\r\n return {\r\n row: coords[0],\r\n column: coords[1],\r\n value: parseCellValue(value, type, {\r\n getInlineStringValue: () => getCellInlineStringValue(sheet, node),\r\n getInlineStringXml: () => getOuterXml(node),\r\n getStyleId: () => node.getAttribute('s'),\r\n styles,\r\n values,\r\n properties,\r\n options\r\n })\r\n }\r\n}"],"mappings":"AAAA,OAAOA,cAAc,MAAM,qBAAqB;AAEhD,SACEC,oBAAoB,QACf,kBAAkB;AAEzB,SACEC,YAAY,EACZC,wBAAwB,QACnB,gBAAgB;AAEvB,SACEC,WAAW,QACN,eAAe;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,SAASA,CAACC,IAAI,EAAEC,KAAK,EAAEC,GAAG,EAAEC,MAAM,EAAEC,MAAM,EAAEC,UAAU,EAAEC,OAAO,EAAE;EACvF,IAAMC,MAAM,GAAGZ,oBAAoB,CAACK,IAAI,CAACQ,YAAY,CAAC,GAAG,CAAC,CAAC;EAE3D,IAAMC,YAAY,GAAGb,YAAY,CAACK,KAAK,EAAED,IAAI,CAAC;;EAE9C;EACA;EACA;EACA,IAAIU,KAAK,GAAGD,YAAY,IAAIA,YAAY,CAACE,WAAW;EAEpD,IAAIC,IAAI;EACR,IAAIZ,IAAI,CAACa,YAAY,CAAC,GAAG,CAAC,EAAE;IAC1BD,IAAI,GAAGZ,IAAI,CAACQ,YAAY,CAAC,GAAG,CAAC;EAC/B;EAEA,OAAO;IACLM,GAAG,EAAEP,MAAM,CAAC,CAAC,CAAC;IACdQ,MAAM,EAAER,MAAM,CAAC,CAAC,CAAC;IACjBG,KAAK,EAAEhB,cAAc,CAACgB,KAAK,EAAEE,IAAI,EAAE;MACjCI,oBAAoB,EAAE,SAAAA,qBAAA;QAAA,OAAMnB,wBAAwB,CAACI,KAAK,EAAED,IAAI,CAAC;MAAA;MACjEiB,kBAAkB,EAAE,SAAAA,mBAAA;QAAA,OAAMnB,WAAW,CAACE,IAAI,CAAC;MAAA;MAC3CkB,UAAU,EAAE,SAAAA,WAAA;QAAA,OAAMlB,IAAI,CAACQ,YAAY,CAAC,GAAG,CAAC;MAAA;MACxCJ,MAAM,EAANA,MAAM;MACND,MAAM,EAANA,MAAM;MACNE,UAAU,EAAVA,UAAU;MACVC,OAAO,EAAPA;IACF,CAAC;EACH,CAAC;AACH"}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import parseDate from './parseDate.js';
|
|
2
|
-
import isDateTimestamp from './isDateTimestamp.js';
|
|
2
|
+
import isDateTimestamp from './isDateTimestamp.js';
|
|
3
3
|
|
|
4
|
+
// Parses a string `value` of a cell.
|
|
4
5
|
export default function parseCellValue(value, type, _ref) {
|
|
5
6
|
var getInlineStringValue = _ref.getInlineStringValue,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
getInlineStringXml = _ref.getInlineStringXml,
|
|
8
|
+
getStyleId = _ref.getStyleId,
|
|
9
|
+
styles = _ref.styles,
|
|
10
|
+
values = _ref.values,
|
|
11
|
+
properties = _ref.properties,
|
|
12
|
+
options = _ref.options;
|
|
13
13
|
if (!type) {
|
|
14
14
|
// Default cell type is "n" (numeric).
|
|
15
15
|
// http://www.datypic.com/sc/ooxml/t-ssml_CT_Cell.html
|
|
16
16
|
type = 'n';
|
|
17
|
-
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Available Excel cell types:
|
|
18
20
|
// https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md
|
|
19
21
|
//
|
|
20
22
|
// Some other document (seems to be old):
|
|
21
23
|
// http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/ST_CellType.html
|
|
22
24
|
//
|
|
23
|
-
|
|
24
|
-
|
|
25
25
|
switch (type) {
|
|
26
26
|
// XLSX tends to store all strings as "shared" (indexed) ones
|
|
27
27
|
// using "s" cell type (for saving on strage space).
|
|
@@ -30,46 +30,41 @@ export default function parseCellValue(value, type, _ref) {
|
|
|
30
30
|
case 'str':
|
|
31
31
|
value = parseString(value, options);
|
|
32
32
|
break;
|
|
33
|
+
|
|
33
34
|
// Sometimes, XLSX stores strings as "inline" strings rather than "shared" (indexed) ones.
|
|
34
35
|
// Perhaps the specification doesn't force it to use one or another.
|
|
35
36
|
// Example: `<sheetData><row r="1"><c r="A1" s="1" t="inlineStr"><is><t>Test 123</t></is></c></row></sheetData>`.
|
|
36
|
-
|
|
37
37
|
case 'inlineStr':
|
|
38
38
|
value = getInlineStringValue();
|
|
39
|
-
|
|
40
39
|
if (value === undefined) {
|
|
41
40
|
throw new Error("Unsupported \"inline string\" cell value structure: ".concat(getInlineStringXml()));
|
|
42
41
|
}
|
|
43
|
-
|
|
44
42
|
value = parseString(value, options);
|
|
45
43
|
break;
|
|
44
|
+
|
|
46
45
|
// XLSX tends to store string values as "shared" (indexed) ones.
|
|
47
46
|
// "Shared" strings is a way for an Excel editor to reduce
|
|
48
47
|
// the file size by storing "commonly used" strings in a dictionary
|
|
49
48
|
// and then referring to such strings by their index in that dictionary.
|
|
50
49
|
// Example: `<sheetData><row r="1"><c r="A1" s="1" t="s"><v>0</v></c></row></sheetData>`.
|
|
51
|
-
|
|
52
50
|
case 's':
|
|
53
51
|
// If a cell has no value then there's no `<c/>` element for it.
|
|
54
52
|
// If a `<c/>` element exists then it's not empty.
|
|
55
53
|
// The `<v/>`alue is a key in the "shared strings" dictionary of the
|
|
56
54
|
// XLSX file, so look it up in the `values` dictionary by the numeric key.
|
|
57
55
|
var sharedStringIndex = Number(value);
|
|
58
|
-
|
|
59
56
|
if (isNaN(sharedStringIndex)) {
|
|
60
57
|
throw new Error("Invalid \"shared\" string index: ".concat(value));
|
|
61
58
|
}
|
|
62
|
-
|
|
63
59
|
if (sharedStringIndex >= values.length) {
|
|
64
60
|
throw new Error("An out-of-bounds \"shared\" string index: ".concat(value));
|
|
65
61
|
}
|
|
66
|
-
|
|
67
62
|
value = values[sharedStringIndex];
|
|
68
63
|
value = parseString(value, options);
|
|
69
64
|
break;
|
|
65
|
+
|
|
70
66
|
// Boolean (TRUE/FALSE) values are stored as either "1" or "0"
|
|
71
67
|
// in cells of type "b".
|
|
72
|
-
|
|
73
68
|
case 'b':
|
|
74
69
|
if (value === '1') {
|
|
75
70
|
value = true;
|
|
@@ -78,55 +73,50 @@ export default function parseCellValue(value, type, _ref) {
|
|
|
78
73
|
} else {
|
|
79
74
|
throw new Error("Unsupported \"boolean\" cell value: ".concat(value));
|
|
80
75
|
}
|
|
81
|
-
|
|
82
76
|
break;
|
|
77
|
+
|
|
83
78
|
// XLSX specification seems to support cells of type "z":
|
|
84
79
|
// blank "stub" cells that should be ignored by data processing utilities.
|
|
85
|
-
|
|
86
80
|
case 'z':
|
|
87
81
|
value = undefined;
|
|
88
82
|
break;
|
|
83
|
+
|
|
89
84
|
// XLSX specification also defines cells of type "e" containing a numeric "error" code.
|
|
90
85
|
// It's not clear what that means though.
|
|
91
86
|
// They also wrote: "and `w` property stores its common name".
|
|
92
87
|
// It's unclear what they meant by that.
|
|
93
|
-
|
|
94
88
|
case 'e':
|
|
95
89
|
value = decodeError(value);
|
|
96
90
|
break;
|
|
91
|
+
|
|
97
92
|
// XLSX supports date cells of type "d", though seems like it (almost?) never
|
|
98
93
|
// uses it for storing dates, preferring "n" numeric timestamp cells instead.
|
|
99
94
|
// The value of a "d" cell is supposedly a string in "ISO 8601" format.
|
|
100
95
|
// I haven't seen an XLSX file having such cells.
|
|
101
96
|
// Example: `<sheetData><row r="1"><c r="A1" s="1" t="d"><v>2021-06-10T00:47:45.700Z</v></c></row></sheetData>`.
|
|
102
|
-
|
|
103
97
|
case 'd':
|
|
104
98
|
if (value === undefined) {
|
|
105
99
|
break;
|
|
106
100
|
}
|
|
107
|
-
|
|
108
101
|
var parsedDate = new Date(value);
|
|
109
|
-
|
|
110
102
|
if (isNaN(parsedDate.valueOf())) {
|
|
111
103
|
throw new Error("Unsupported \"date\" cell value: ".concat(value));
|
|
112
104
|
}
|
|
113
|
-
|
|
114
105
|
value = parsedDate;
|
|
115
106
|
break;
|
|
116
|
-
// Numeric cells have type "n".
|
|
117
107
|
|
|
108
|
+
// Numeric cells have type "n".
|
|
118
109
|
case 'n':
|
|
119
110
|
if (value === undefined) {
|
|
120
111
|
break;
|
|
121
112
|
}
|
|
122
|
-
|
|
123
|
-
|
|
113
|
+
var isDateTimestampNumber = isDateTimestamp(getStyleId(), styles, options);
|
|
114
|
+
// XLSX does have "d" type for dates, but it's not commonly used.
|
|
124
115
|
// Instead, it prefers using "n" type for storing dates as timestamps.
|
|
125
|
-
|
|
126
116
|
if (isDateTimestampNumber) {
|
|
127
117
|
// Parse the number from string.
|
|
128
|
-
value = parseNumberDefault(value);
|
|
129
|
-
|
|
118
|
+
value = parseNumberDefault(value);
|
|
119
|
+
// Parse the number as a date timestamp.
|
|
130
120
|
value = parseDate(value, properties);
|
|
131
121
|
} else {
|
|
132
122
|
// Parse the number from string.
|
|
@@ -134,56 +124,45 @@ export default function parseCellValue(value, type, _ref) {
|
|
|
134
124
|
// https://gitlab.com/catamphetamine/read-excel-file/-/issues/85
|
|
135
125
|
value = (options.parseNumber || parseNumberDefault)(value);
|
|
136
126
|
}
|
|
137
|
-
|
|
138
127
|
break;
|
|
139
|
-
|
|
140
128
|
default:
|
|
141
129
|
throw new TypeError("Cell type not supported: ".concat(type));
|
|
142
|
-
}
|
|
143
|
-
|
|
130
|
+
}
|
|
144
131
|
|
|
132
|
+
// Convert empty values to `null`.
|
|
145
133
|
if (value === undefined) {
|
|
146
134
|
value = null;
|
|
147
135
|
}
|
|
148
|
-
|
|
149
136
|
return value;
|
|
150
|
-
}
|
|
151
|
-
// https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md
|
|
137
|
+
}
|
|
152
138
|
|
|
139
|
+
// Decodes numeric error code to a string code.
|
|
140
|
+
// https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md
|
|
153
141
|
function decodeError(errorCode) {
|
|
154
142
|
// While the error values are determined by the application,
|
|
155
143
|
// the following are some example error values that could be used:
|
|
156
144
|
switch (errorCode) {
|
|
157
145
|
case 0x00:
|
|
158
146
|
return '#NULL!';
|
|
159
|
-
|
|
160
147
|
case 0x07:
|
|
161
148
|
return '#DIV/0!';
|
|
162
|
-
|
|
163
149
|
case 0x0F:
|
|
164
150
|
return '#VALUE!';
|
|
165
|
-
|
|
166
151
|
case 0x17:
|
|
167
152
|
return '#REF!';
|
|
168
|
-
|
|
169
153
|
case 0x1D:
|
|
170
154
|
return '#NAME?';
|
|
171
|
-
|
|
172
155
|
case 0x24:
|
|
173
156
|
return '#NUM!';
|
|
174
|
-
|
|
175
157
|
case 0x2A:
|
|
176
158
|
return '#N/A';
|
|
177
|
-
|
|
178
159
|
case 0x2B:
|
|
179
160
|
return '#GETTING_DATA';
|
|
180
|
-
|
|
181
161
|
default:
|
|
182
162
|
// Such error code doesn't exist. I made it up.
|
|
183
163
|
return "#ERROR_".concat(errorCode);
|
|
184
164
|
}
|
|
185
165
|
}
|
|
186
|
-
|
|
187
166
|
function parseString(value, options) {
|
|
188
167
|
// In some weird cases, a developer might want to disable
|
|
189
168
|
// the automatic trimming of all strings.
|
|
@@ -192,27 +171,23 @@ function parseString(value, options) {
|
|
|
192
171
|
if (options.trim !== false) {
|
|
193
172
|
value = value.trim();
|
|
194
173
|
}
|
|
195
|
-
|
|
196
174
|
if (value === '') {
|
|
197
175
|
value = undefined;
|
|
198
176
|
}
|
|
199
|
-
|
|
200
177
|
return value;
|
|
201
|
-
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Parses a number from string.
|
|
202
181
|
// Throws an error if the number couldn't be parsed.
|
|
203
182
|
// When parsing floating-point number, is affected by
|
|
204
183
|
// the javascript number encoding precision issues:
|
|
205
184
|
// https://www.youtube.com/watch?v=2gIxbTn7GSc
|
|
206
185
|
// https://www.avioconsulting.com/blog/overcoming-javascript-numeric-precision-issues
|
|
207
|
-
|
|
208
|
-
|
|
209
186
|
function parseNumberDefault(stringifiedNumber) {
|
|
210
187
|
var parsedNumber = Number(stringifiedNumber);
|
|
211
|
-
|
|
212
188
|
if (isNaN(parsedNumber)) {
|
|
213
189
|
throw new Error("Invalid \"numeric\" cell value: ".concat(stringifiedNumber));
|
|
214
190
|
}
|
|
215
|
-
|
|
216
191
|
return parsedNumber;
|
|
217
192
|
}
|
|
218
193
|
//# sourceMappingURL=parseCellValue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseCellValue.js","names":["parseDate","isDateTimestamp","parseCellValue","value","type","getInlineStringValue","getInlineStringXml","getStyleId","styles","values","properties","options","parseString","undefined","Error","sharedStringIndex","Number","isNaN","length","decodeError","parsedDate","Date","valueOf","isDateTimestampNumber","parseNumberDefault","parseNumber","TypeError","errorCode","trim","stringifiedNumber","parsedNumber"],"sources":["../../source/read/parseCellValue.js"],"sourcesContent":["import parseDate from './parseDate.js'\r\nimport isDateTimestamp from './isDateTimestamp.js'\r\n\r\n// Parses a string `value` of a cell.\r\nexport default function parseCellValue(value, type, {\r\n getInlineStringValue,\r\n getInlineStringXml,\r\n getStyleId,\r\n styles,\r\n values,\r\n properties,\r\n options\r\n}) {\r\n if (!type) {\r\n // Default cell type is \"n\" (numeric).\r\n // http://www.datypic.com/sc/ooxml/t-ssml_CT_Cell.html\r\n type = 'n'\r\n }\r\n\r\n // Available Excel cell types:\r\n // https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md\r\n //\r\n // Some other document (seems to be old):\r\n // http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/ST_CellType.html\r\n //\r\n switch (type) {\r\n // XLSX tends to store all strings as \"shared\" (indexed) ones\r\n // using \"s\" cell type (for saving on strage space).\r\n // \"str\" cell type is then generally only used for storing\r\n // formula-pre-calculated cell values.\r\n case 'str':\r\n value = parseString(value, options)\r\n break\r\n\r\n // Sometimes, XLSX stores strings as \"inline\" strings rather than \"shared\" (indexed) ones.\r\n // Perhaps the specification doesn't force it to use one or another.\r\n // Example: `<sheetData><row r=\"1\"><c r=\"A1\" s=\"1\" t=\"inlineStr\"><is><t>Test 123</t></is></c></row></sheetData>`.\r\n case 'inlineStr':\r\n value = getInlineStringValue()\r\n if (value === undefined) {\r\n throw new Error(`Unsupported \"inline string\" cell value structure: ${getInlineStringXml()}`)\r\n }\r\n value = parseString(value, options)\r\n break\r\n\r\n // XLSX tends to store string values as \"shared\" (indexed) ones.\r\n // \"Shared\" strings is a way for an Excel editor to reduce\r\n // the file size by storing \"commonly used\" strings in a dictionary\r\n // and then referring to such strings by their index in that dictionary.\r\n // Example: `<sheetData><row r=\"1\"><c r=\"A1\" s=\"1\" t=\"s\"><v>0</v></c></row></sheetData>`.\r\n case 's':\r\n // If a cell has no value then there's no `<c/>` element for it.\r\n // If a `<c/>` element exists then it's not empty.\r\n // The `<v/>`alue is a key in the \"shared strings\" dictionary of the\r\n // XLSX file, so look it up in the `values` dictionary by the numeric key.\r\n const sharedStringIndex = Number(value)\r\n if (isNaN(sharedStringIndex)) {\r\n throw new Error(`Invalid \"shared\" string index: ${value}`)\r\n }\r\n if (sharedStringIndex >= values.length) {\r\n throw new Error(`An out-of-bounds \"shared\" string index: ${value}`)\r\n }\r\n value = values[sharedStringIndex]\r\n value = parseString(value, options)\r\n break\r\n\r\n // Boolean (TRUE/FALSE) values are stored as either \"1\" or \"0\"\r\n // in cells of type \"b\".\r\n case 'b':\r\n if (value === '1') {\r\n value = true\r\n } else if (value === '0') {\r\n value = false\r\n } else {\r\n throw new Error(`Unsupported \"boolean\" cell value: ${value}`)\r\n }\r\n break\r\n\r\n // XLSX specification seems to support cells of type \"z\":\r\n // blank \"stub\" cells that should be ignored by data processing utilities.\r\n case 'z':\r\n value = undefined\r\n break\r\n\r\n // XLSX specification also defines cells of type \"e\" containing a numeric \"error\" code.\r\n // It's not clear what that means though.\r\n // They also wrote: \"and `w` property stores its common name\".\r\n // It's unclear what they meant by that.\r\n case 'e':\r\n value = decodeError(value)\r\n break\r\n\r\n // XLSX supports date cells of type \"d\", though seems like it (almost?) never\r\n // uses it for storing dates, preferring \"n\" numeric timestamp cells instead.\r\n // The value of a \"d\" cell is supposedly a string in \"ISO 8601\" format.\r\n // I haven't seen an XLSX file having such cells.\r\n // Example: `<sheetData><row r=\"1\"><c r=\"A1\" s=\"1\" t=\"d\"><v>2021-06-10T00:47:45.700Z</v></c></row></sheetData>`.\r\n case 'd':\r\n if (value === undefined) {\r\n break\r\n }\r\n const parsedDate = new Date(value)\r\n if (isNaN(parsedDate.valueOf())) {\r\n throw new Error(`Unsupported \"date\" cell value: ${value}`)\r\n }\r\n value = parsedDate\r\n break\r\n\r\n // Numeric cells have type \"n\".\r\n case 'n':\r\n if (value === undefined) {\r\n break\r\n }\r\n const isDateTimestampNumber = isDateTimestamp(getStyleId(), styles, options)\r\n // XLSX does have \"d\" type for dates, but it's not commonly used.\r\n // Instead, it prefers using \"n\" type for storing dates as timestamps.\r\n if (isDateTimestampNumber) {\r\n // Parse the number from string.\r\n value = parseNumberDefault(value)\r\n // Parse the number as a date timestamp.\r\n value = parseDate(value, properties)\r\n } else {\r\n // Parse the number from string.\r\n // Supports custom parsing function to work around javascript number encoding precision issues.\r\n // https://gitlab.com/catamphetamine/read-excel-file/-/issues/85\r\n value = (options.parseNumber || parseNumberDefault)(value)\r\n }\r\n break\r\n\r\n default:\r\n throw new TypeError(`Cell type not supported: ${type}`)\r\n }\r\n\r\n // Convert empty values to `null`.\r\n if (value === undefined) {\r\n value = null\r\n }\r\n\r\n return value\r\n}\r\n\r\n// Decodes numeric error code to a string code.\r\n// https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md\r\nfunction decodeError(errorCode) {\r\n // While the error values are determined by the application,\r\n // the following are some example error values that could be used:\r\n switch (errorCode) {\r\n case 0x00:\r\n return '#NULL!'\r\n case 0x07:\r\n return '#DIV/0!'\r\n case 0x0F:\r\n return '#VALUE!'\r\n case 0x17:\r\n return '#REF!'\r\n case 0x1D:\r\n return '#NAME?'\r\n case 0x24:\r\n return '#NUM!'\r\n case 0x2A:\r\n return '#N/A'\r\n case 0x2B:\r\n return '#GETTING_DATA'\r\n default:\r\n // Such error code doesn't exist. I made it up.\r\n return `#ERROR_${errorCode}`\r\n }\r\n}\r\n\r\nfunction parseString(value, options) {\r\n // In some weird cases, a developer might want to disable\r\n // the automatic trimming of all strings.\r\n // For example, leading spaces might express a tree-like hierarchy.\r\n // https://github.com/catamphetamine/read-excel-file/pull/106#issuecomment-1136062917\r\n if (options.trim !== false) {\r\n value = value.trim()\r\n }\r\n if (value === '') {\r\n value = undefined\r\n }\r\n return value\r\n}\r\n\r\n// Parses a number from string.\r\n// Throws an error if the number couldn't be parsed.\r\n// When parsing floating-point number, is affected by\r\n// the javascript number encoding precision issues:\r\n// https://www.youtube.com/watch?v=2gIxbTn7GSc\r\n// https://www.avioconsulting.com/blog/overcoming-javascript-numeric-precision-issues\r\nfunction parseNumberDefault(stringifiedNumber) {\r\n const parsedNumber = Number(stringifiedNumber)\r\n if (isNaN(parsedNumber)) {\r\n throw new Error(`Invalid \"numeric\" cell value: ${stringifiedNumber}`)\r\n }\r\n return parsedNumber\r\n}"],"mappings":"AAAA,OAAOA,SAAP,MAAsB,gBAAtB;AACA,OAAOC,eAAP,MAA4B,sBAA5B,C,CAEA;;AACA,eAAe,SAASC,cAAT,CAAwBC,KAAxB,EAA+BC,IAA/B,QAQZ;EAAA,IAPDC,oBAOC,QAPDA,oBAOC;EAAA,IANDC,kBAMC,QANDA,kBAMC;EAAA,IALDC,UAKC,QALDA,UAKC;EAAA,IAJDC,MAIC,QAJDA,MAIC;EAAA,IAHDC,MAGC,QAHDA,MAGC;EAAA,IAFDC,UAEC,QAFDA,UAEC;EAAA,IADDC,OACC,QADDA,OACC;;EACD,IAAI,CAACP,IAAL,EAAW;IACT;IACA;IACAA,IAAI,GAAG,GAAP;EACD,CALA,CAOD;EACA;EACA;EACA;EACA;EACA;;;EACA,QAAQA,IAAR;IACE;IACA;IACA;IACA;IACA,KAAK,KAAL;MACED,KAAK,GAAGS,WAAW,CAACT,KAAD,EAAQQ,OAAR,CAAnB;MACA;IAEF;IACA;IACA;;IACA,KAAK,WAAL;MACER,KAAK,GAAGE,oBAAoB,EAA5B;;MACA,IAAIF,KAAK,KAAKU,SAAd,EAAyB;QACvB,MAAM,IAAIC,KAAJ,+DAA+DR,kBAAkB,EAAjF,EAAN;MACD;;MACDH,KAAK,GAAGS,WAAW,CAACT,KAAD,EAAQQ,OAAR,CA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,CAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASqB,kBAAT,CAA4BK,iBAA5B,EAA+C;EAC7C,IAAMC,YAAY,GAAGd,MAAM,CAACa,iBAAD,CAA3B;;EACA,IAAIZ,KAAK,CAACa,YAAD,CAAT,EAAyB;IACvB,MAAM,IAAIhB,KAAJ,2CAA2Ce,iBAA3C,EAAN;EACD;;EACD,OAAOC,YAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"parseCellValue.js","names":["parseDate","isDateTimestamp","parseCellValue","value","type","_ref","getInlineStringValue","getInlineStringXml","getStyleId","styles","values","properties","options","parseString","undefined","Error","concat","sharedStringIndex","Number","isNaN","length","decodeError","parsedDate","Date","valueOf","isDateTimestampNumber","parseNumberDefault","parseNumber","TypeError","errorCode","trim","stringifiedNumber","parsedNumber"],"sources":["../../source/read/parseCellValue.js"],"sourcesContent":["import parseDate from './parseDate.js'\r\nimport isDateTimestamp from './isDateTimestamp.js'\r\n\r\n// Parses a string `value` of a cell.\r\nexport default function parseCellValue(value, type, {\r\n getInlineStringValue,\r\n getInlineStringXml,\r\n getStyleId,\r\n styles,\r\n values,\r\n properties,\r\n options\r\n}) {\r\n if (!type) {\r\n // Default cell type is \"n\" (numeric).\r\n // http://www.datypic.com/sc/ooxml/t-ssml_CT_Cell.html\r\n type = 'n'\r\n }\r\n\r\n // Available Excel cell types:\r\n // https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md\r\n //\r\n // Some other document (seems to be old):\r\n // http://webapp.docx4java.org/OnlineDemo/ecma376/SpreadsheetML/ST_CellType.html\r\n //\r\n switch (type) {\r\n // XLSX tends to store all strings as \"shared\" (indexed) ones\r\n // using \"s\" cell type (for saving on strage space).\r\n // \"str\" cell type is then generally only used for storing\r\n // formula-pre-calculated cell values.\r\n case 'str':\r\n value = parseString(value, options)\r\n break\r\n\r\n // Sometimes, XLSX stores strings as \"inline\" strings rather than \"shared\" (indexed) ones.\r\n // Perhaps the specification doesn't force it to use one or another.\r\n // Example: `<sheetData><row r=\"1\"><c r=\"A1\" s=\"1\" t=\"inlineStr\"><is><t>Test 123</t></is></c></row></sheetData>`.\r\n case 'inlineStr':\r\n value = getInlineStringValue()\r\n if (value === undefined) {\r\n throw new Error(`Unsupported \"inline string\" cell value structure: ${getInlineStringXml()}`)\r\n }\r\n value = parseString(value, options)\r\n break\r\n\r\n // XLSX tends to store string values as \"shared\" (indexed) ones.\r\n // \"Shared\" strings is a way for an Excel editor to reduce\r\n // the file size by storing \"commonly used\" strings in a dictionary\r\n // and then referring to such strings by their index in that dictionary.\r\n // Example: `<sheetData><row r=\"1\"><c r=\"A1\" s=\"1\" t=\"s\"><v>0</v></c></row></sheetData>`.\r\n case 's':\r\n // If a cell has no value then there's no `<c/>` element for it.\r\n // If a `<c/>` element exists then it's not empty.\r\n // The `<v/>`alue is a key in the \"shared strings\" dictionary of the\r\n // XLSX file, so look it up in the `values` dictionary by the numeric key.\r\n const sharedStringIndex = Number(value)\r\n if (isNaN(sharedStringIndex)) {\r\n throw new Error(`Invalid \"shared\" string index: ${value}`)\r\n }\r\n if (sharedStringIndex >= values.length) {\r\n throw new Error(`An out-of-bounds \"shared\" string index: ${value}`)\r\n }\r\n value = values[sharedStringIndex]\r\n value = parseString(value, options)\r\n break\r\n\r\n // Boolean (TRUE/FALSE) values are stored as either \"1\" or \"0\"\r\n // in cells of type \"b\".\r\n case 'b':\r\n if (value === '1') {\r\n value = true\r\n } else if (value === '0') {\r\n value = false\r\n } else {\r\n throw new Error(`Unsupported \"boolean\" cell value: ${value}`)\r\n }\r\n break\r\n\r\n // XLSX specification seems to support cells of type \"z\":\r\n // blank \"stub\" cells that should be ignored by data processing utilities.\r\n case 'z':\r\n value = undefined\r\n break\r\n\r\n // XLSX specification also defines cells of type \"e\" containing a numeric \"error\" code.\r\n // It's not clear what that means though.\r\n // They also wrote: \"and `w` property stores its common name\".\r\n // It's unclear what they meant by that.\r\n case 'e':\r\n value = decodeError(value)\r\n break\r\n\r\n // XLSX supports date cells of type \"d\", though seems like it (almost?) never\r\n // uses it for storing dates, preferring \"n\" numeric timestamp cells instead.\r\n // The value of a \"d\" cell is supposedly a string in \"ISO 8601\" format.\r\n // I haven't seen an XLSX file having such cells.\r\n // Example: `<sheetData><row r=\"1\"><c r=\"A1\" s=\"1\" t=\"d\"><v>2021-06-10T00:47:45.700Z</v></c></row></sheetData>`.\r\n case 'd':\r\n if (value === undefined) {\r\n break\r\n }\r\n const parsedDate = new Date(value)\r\n if (isNaN(parsedDate.valueOf())) {\r\n throw new Error(`Unsupported \"date\" cell value: ${value}`)\r\n }\r\n value = parsedDate\r\n break\r\n\r\n // Numeric cells have type \"n\".\r\n case 'n':\r\n if (value === undefined) {\r\n break\r\n }\r\n const isDateTimestampNumber = isDateTimestamp(getStyleId(), styles, options)\r\n // XLSX does have \"d\" type for dates, but it's not commonly used.\r\n // Instead, it prefers using \"n\" type for storing dates as timestamps.\r\n if (isDateTimestampNumber) {\r\n // Parse the number from string.\r\n value = parseNumberDefault(value)\r\n // Parse the number as a date timestamp.\r\n value = parseDate(value, properties)\r\n } else {\r\n // Parse the number from string.\r\n // Supports custom parsing function to work around javascript number encoding precision issues.\r\n // https://gitlab.com/catamphetamine/read-excel-file/-/issues/85\r\n value = (options.parseNumber || parseNumberDefault)(value)\r\n }\r\n break\r\n\r\n default:\r\n throw new TypeError(`Cell type not supported: ${type}`)\r\n }\r\n\r\n // Convert empty values to `null`.\r\n if (value === undefined) {\r\n value = null\r\n }\r\n\r\n return value\r\n}\r\n\r\n// Decodes numeric error code to a string code.\r\n// https://github.com/SheetJS/sheetjs/blob/19620da30be2a7d7b9801938a0b9b1fd3c4c4b00/docbits/52_datatype.md\r\nfunction decodeError(errorCode) {\r\n // While the error values are determined by the application,\r\n // the following are some example error values that could be used:\r\n switch (errorCode) {\r\n case 0x00:\r\n return '#NULL!'\r\n case 0x07:\r\n return '#DIV/0!'\r\n case 0x0F:\r\n return '#VALUE!'\r\n case 0x17:\r\n return '#REF!'\r\n case 0x1D:\r\n return '#NAME?'\r\n case 0x24:\r\n return '#NUM!'\r\n case 0x2A:\r\n return '#N/A'\r\n case 0x2B:\r\n return '#GETTING_DATA'\r\n default:\r\n // Such error code doesn't exist. I made it up.\r\n return `#ERROR_${errorCode}`\r\n }\r\n}\r\n\r\nfunction parseString(value, options) {\r\n // In some weird cases, a developer might want to disable\r\n // the automatic trimming of all strings.\r\n // For example, leading spaces might express a tree-like hierarchy.\r\n // https://github.com/catamphetamine/read-excel-file/pull/106#issuecomment-1136062917\r\n if (options.trim !== false) {\r\n value = value.trim()\r\n }\r\n if (value === '') {\r\n value = undefined\r\n }\r\n return value\r\n}\r\n\r\n// Parses a number from string.\r\n// Throws an error if the number couldn't be parsed.\r\n// When parsing floating-point number, is affected by\r\n// the javascript number encoding precision issues:\r\n// https://www.youtube.com/watch?v=2gIxbTn7GSc\r\n// https://www.avioconsulting.com/blog/overcoming-javascript-numeric-precision-issues\r\nfunction parseNumberDefault(stringifiedNumber) {\r\n const parsedNumber = Number(stringifiedNumber)\r\n if (isNaN(parsedNumber)) {\r\n throw new Error(`Invalid \"numeric\" cell value: ${stringifiedNumber}`)\r\n }\r\n return parsedNumber\r\n}"],"mappings":"AAAA,OAAOA,SAAS,MAAM,gBAAgB;AACtC,OAAOC,eAAe,MAAM,sBAAsB;;AAElD;AACA,eAAe,SAASC,cAAcA,CAACC,KAAK,EAAEC,IAAI,EAAAC,IAAA,EAQ/C;EAAA,IAPDC,oBAAoB,GAAAD,IAAA,CAApBC,oBAAoB;IACpBC,kBAAkB,GAAAF,IAAA,CAAlBE,kBAAkB;IAClBC,UAAU,GAAAH,IAAA,CAAVG,UAAU;IACVC,MAAM,GAAAJ,IAAA,CAANI,MAAM;IACNC,MAAM,GAAAL,IAAA,CAANK,MAAM;IACNC,UAAU,GAAAN,IAAA,CAAVM,UAAU;IACVC,OAAO,GAAAP,IAAA,CAAPO,OAAO;EAEP,IAAI,CAACR,IA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SAAS;IAClB,KAAK,IAAI;MACP,OAAO,OAAO;IAChB,KAAK,IAAI;MACP,OAAO,QAAQ;IACjB,KAAK,IAAI;MACP,OAAO,OAAO;IAChB,KAAK,IAAI;MACP,OAAO,MAAM;IACf,KAAK,IAAI;MACP,OAAO,eAAe;IACxB;MACE;MACA,iBAAAb,MAAA,CAAiBa,SAAS;EAC9B;AACF;AAEA,SAAShB,WAAWA,CAACV,KAAK,EAAES,OAAO,EAAE;EACnC;EACA;EACA;EACA;EACA,IAAIA,OAAO,CAACkB,IAAI,KAAK,KAAK,EAAE;IAC1B3B,KAAK,GAAGA,KAAK,CAAC2B,IAAI,CAAC,CAAC;EACtB;EACA,IAAI3B,KAAK,KAAK,EAAE,EAAE;IAChBA,KAAK,GAAGW,SAAS;EACnB;EACA,OAAOX,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,SAASuB,kBAAkBA,CAACK,iBAAiB,EAAE;EAC7C,IAAMC,YAAY,GAAGd,MAAM,CAACa,iBAAiB,CAAC;EAC9C,IAAIZ,KAAK,CAACa,YAAY,CAAC,EAAE;IACvB,MAAM,IAAIjB,KAAK,oCAAAC,MAAA,CAAkCe,iBAAiB,CAAE,CAAC;EACvE;EACA,OAAOC,YAAY;AACrB"}
|
|
@@ -2,16 +2,16 @@ import parseCell from './parseCell.js';
|
|
|
2
2
|
import { getCells, getMergedCells } from '../xml/xlsx.js';
|
|
3
3
|
export default function parseCells(sheet, xml, values, styles, properties, options) {
|
|
4
4
|
var cells = getCells(sheet);
|
|
5
|
-
|
|
6
5
|
if (cells.length === 0) {
|
|
7
6
|
return [];
|
|
8
|
-
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// const mergedCells = getMergedCells(sheet)
|
|
9
10
|
// for (const mergedCell of mergedCells) {
|
|
10
11
|
// const [from, to] = mergedCell.split(':').map(parseCellCoordinates)
|
|
11
12
|
// console.log('Merged Cell.', 'From:', from, 'To:', to)
|
|
12
13
|
// }
|
|
13
14
|
|
|
14
|
-
|
|
15
15
|
return cells.map(function (node) {
|
|
16
16
|
return parseCell(node, sheet, xml, values, styles, properties, options);
|
|
17
17
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseCells.js","names":["parseCell","getCells","getMergedCells","parseCells","sheet","xml","values","styles","properties","options","cells","length","map","node"],"sources":["../../source/read/parseCells.js"],"sourcesContent":["import parseCell from './parseCell.js'\r\n\r\nimport {\r\n getCells,\r\n getMergedCells\r\n} from '../xml/xlsx.js'\r\n\r\nexport default function parseCells(sheet, xml, values, styles, properties, options) {\r\n const cells = getCells(sheet)\r\n\r\n if (cells.length === 0) {\r\n return []\r\n }\r\n\r\n // const mergedCells = getMergedCells(sheet)\r\n // for (const mergedCell of mergedCells) {\r\n // const [from, to] = mergedCell.split(':').map(parseCellCoordinates)\r\n // console.log('Merged Cell.', 'From:', from, 'To:', to)\r\n // }\r\n\r\n return cells.map((node) => {\r\n return parseCell(node, sheet, xml, values, styles, properties, options)\r\n })\r\n}"],"mappings":"AAAA,OAAOA,
|
|
1
|
+
{"version":3,"file":"parseCells.js","names":["parseCell","getCells","getMergedCells","parseCells","sheet","xml","values","styles","properties","options","cells","length","map","node"],"sources":["../../source/read/parseCells.js"],"sourcesContent":["import parseCell from './parseCell.js'\r\n\r\nimport {\r\n getCells,\r\n getMergedCells\r\n} from '../xml/xlsx.js'\r\n\r\nexport default function parseCells(sheet, xml, values, styles, properties, options) {\r\n const cells = getCells(sheet)\r\n\r\n if (cells.length === 0) {\r\n return []\r\n }\r\n\r\n // const mergedCells = getMergedCells(sheet)\r\n // for (const mergedCell of mergedCells) {\r\n // const [from, to] = mergedCell.split(':').map(parseCellCoordinates)\r\n // console.log('Merged Cell.', 'From:', from, 'To:', to)\r\n // }\r\n\r\n return cells.map((node) => {\r\n return parseCell(node, sheet, xml, values, styles, properties, options)\r\n })\r\n}"],"mappings":"AAAA,OAAOA,SAAS,MAAM,gBAAgB;AAEtC,SACEC,QAAQ,EACRC,cAAc,QACT,gBAAgB;AAEvB,eAAe,SAASC,UAAUA,CAACC,KAAK,EAAEC,GAAG,EAAEC,MAAM,EAAEC,MAAM,EAAEC,UAAU,EAAEC,OAAO,EAAE;EAClF,IAAMC,KAAK,GAAGT,QAAQ,CAACG,KAAK,CAAC;EAE7B,IAAIM,KAAK,CAACC,MAAM,KAAK,CAAC,EAAE;IACtB,OAAO,EAAE;EACX;;EAEA;EACA;EACA;EACA;EACA;;EAEA,OAAOD,KAAK,CAACE,GAAG,CAAC,UAACC,IAAI,EAAK;IACzB,OAAOb,SAAS,CAACa,IAAI,EAAET,KAAK,EAAEC,GAAG,EAAEC,MAAM,EAAEC,MAAM,EAAEC,UAAU,EAAEC,OAAO,CAAC;EACzE,CAAC,CAAC;AACJ"}
|
|
@@ -9,7 +9,9 @@ export default function parseExcelDate(excelSerialDate, options) {
|
|
|
9
9
|
// https://support.microsoft.com/en-gb/help/214330/differences-between-the-1900-and-the-1904-date-system-in-excel
|
|
10
10
|
if (options && options.epoch1904) {
|
|
11
11
|
excelSerialDate += 1462;
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// "Excel serial date" is just
|
|
13
15
|
// the count of days since `01/01/1900`
|
|
14
16
|
// (seems that it may be even fractional).
|
|
15
17
|
//
|
|
@@ -18,9 +20,9 @@ export default function parseExcelDate(excelSerialDate, options) {
|
|
|
18
20
|
// till `01/01/1970` (Unix epoch).
|
|
19
21
|
// Accounts for leap years
|
|
20
22
|
// (19 of them, yielding 19 extra days).
|
|
23
|
+
var daysBeforeUnixEpoch = 70 * 365 + 19;
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
var daysBeforeUnixEpoch = 70 * 365 + 19; // An hour, approximately, because a minute
|
|
25
|
+
// An hour, approximately, because a minute
|
|
24
26
|
// may be longer than 60 seconds, due to "leap seconds".
|
|
25
27
|
//
|
|
26
28
|
// Still, Javascript `Date` (and UNIX time in general) intentionally
|
|
@@ -59,7 +61,6 @@ export default function parseExcelDate(excelSerialDate, options) {
|
|
|
59
61
|
// https://en.wikipedia.org/wiki/Leap_year
|
|
60
62
|
// https://en.wikipedia.org/wiki/Leap_second
|
|
61
63
|
//
|
|
62
|
-
|
|
63
64
|
var hour = 60 * 60 * 1000;
|
|
64
65
|
return new Date(Math.round((excelSerialDate - daysBeforeUnixEpoch) * 24 * hour));
|
|
65
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseDate.js","names":["parseExcelDate","excelSerialDate","options","epoch1904","daysBeforeUnixEpoch","hour","Date","Math","round"],"sources":["../../source/read/parseDate.js"],"sourcesContent":["// Parses an Excel Date (\"serial\") into a corresponding javascript Date in UTC+0 timezone.\r\n// (with time equal to 00:00)\r\n//\r\n// https://www.pcworld.com/article/3063622/software/mastering-excel-date-time-serial-numbers-networkdays-datevalue-and-more.html\r\n// \"If you need to calculate dates in your spreadsheets,\r\n// Excel uses its own unique system, which it calls Serial Numbers\".\r\n//\r\nexport default function parseExcelDate(excelSerialDate, options) {\r\n // https://support.microsoft.com/en-gb/help/214330/differences-between-the-1900-and-the-1904-date-system-in-excel\r\n if (options && options.epoch1904) {\r\n excelSerialDate += 1462\r\n }\r\n\r\n // \"Excel serial date\" is just\r\n // the count of days since `01/01/1900`\r\n // (seems that it may be even fractional).\r\n //\r\n // The count of days elapsed\r\n // since `01/01/1900` (Excel epoch)\r\n // till `01/01/1970` (Unix epoch).\r\n // Accounts for leap years\r\n // (19 of them, yielding 19 extra days).\r\n const daysBeforeUnixEpoch = 70 * 365 + 19\r\n\r\n // An hour, approximately, because a minute\r\n // may be longer than 60 seconds, due to \"leap seconds\".\r\n //\r\n // Still, Javascript `Date` (and UNIX time in general) intentionally\r\n // drops the concept of \"leap seconds\" in order to make things simpler.\r\n // So it's fine.\r\n // https://stackoverflow.com/questions/53019726/where-are-the-leap-seconds-in-javascript\r\n //\r\n // \"The JavaScript Date object specifically adheres to the concept of Unix Time\r\n // (albeit with higher precision). This is part of the POSIX specification,\r\n // and thus is sometimes called \"POSIX Time\". It does not count leap seconds,\r\n // but rather assumes every day had exactly 86,400 seconds. You can read about\r\n // this in section 20.3.1.1 of the current ECMAScript specification, which states:\r\n //\r\n // \"Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC.\r\n // In time values leap seconds are ignored. It is assumed that there are exactly\r\n // 86,400,000 milliseconds per day.\"\r\n //\r\n // The fact is, that the unpredictable nature of leap seconds makes them very\r\n // difficult to work with in APIs. One can't generally pass timestamps around\r\n // that need leap seconds tables to be interpreted correctly, and expect that\r\n // one system will interpret them the same as another. For example, while your\r\n // example timestamp 1483228826 is 2017-01-01T00:00:00Z on your system,\r\n // it would be interpreted as 2017-01-01T00:00:26Z on POSIX based systems,\r\n // or systems without leap second tables. So they aren't portable.\r\n // Even on systems that have full updated tables, there's no telling what those\r\n // tables will contain in the future (beyond the 6-month IERS announcement period),\r\n // so I can't produce a future timestamp without risk that it may eventually change.\r\n //\r\n // To be clear - to support leap seconds in a programming language, the implementation\r\n // must go out of its way to do so, and must make tradeoffs that are not always acceptable.\r\n // Though there are exceptions, the general position is to not support them - not because\r\n // of any subversion or active countermeasures, but because supporting them properly is much,\r\n // much harder.\"\r\n //\r\n // https://en.wikipedia.org/wiki/Unix_time#Leap_seconds\r\n // https://en.wikipedia.org/wiki/Leap_year\r\n // https://en.wikipedia.org/wiki/Leap_second\r\n //\r\n const hour = 60 * 60 * 1000\r\n\r\n return new Date(Math.round((excelSerialDate - daysBeforeUnixEpoch) * 24 * hour))\r\n}"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,
|
|
1
|
+
{"version":3,"file":"parseDate.js","names":["parseExcelDate","excelSerialDate","options","epoch1904","daysBeforeUnixEpoch","hour","Date","Math","round"],"sources":["../../source/read/parseDate.js"],"sourcesContent":["// Parses an Excel Date (\"serial\") into a corresponding javascript Date in UTC+0 timezone.\r\n// (with time equal to 00:00)\r\n//\r\n// https://www.pcworld.com/article/3063622/software/mastering-excel-date-time-serial-numbers-networkdays-datevalue-and-more.html\r\n// \"If you need to calculate dates in your spreadsheets,\r\n// Excel uses its own unique system, which it calls Serial Numbers\".\r\n//\r\nexport default function parseExcelDate(excelSerialDate, options) {\r\n // https://support.microsoft.com/en-gb/help/214330/differences-between-the-1900-and-the-1904-date-system-in-excel\r\n if (options && options.epoch1904) {\r\n excelSerialDate += 1462\r\n }\r\n\r\n // \"Excel serial date\" is just\r\n // the count of days since `01/01/1900`\r\n // (seems that it may be even fractional).\r\n //\r\n // The count of days elapsed\r\n // since `01/01/1900` (Excel epoch)\r\n // till `01/01/1970` (Unix epoch).\r\n // Accounts for leap years\r\n // (19 of them, yielding 19 extra days).\r\n const daysBeforeUnixEpoch = 70 * 365 + 19\r\n\r\n // An hour, approximately, because a minute\r\n // may be longer than 60 seconds, due to \"leap seconds\".\r\n //\r\n // Still, Javascript `Date` (and UNIX time in general) intentionally\r\n // drops the concept of \"leap seconds\" in order to make things simpler.\r\n // So it's fine.\r\n // https://stackoverflow.com/questions/53019726/where-are-the-leap-seconds-in-javascript\r\n //\r\n // \"The JavaScript Date object specifically adheres to the concept of Unix Time\r\n // (albeit with higher precision). This is part of the POSIX specification,\r\n // and thus is sometimes called \"POSIX Time\". It does not count leap seconds,\r\n // but rather assumes every day had exactly 86,400 seconds. You can read about\r\n // this in section 20.3.1.1 of the current ECMAScript specification, which states:\r\n //\r\n // \"Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC.\r\n // In time values leap seconds are ignored. It is assumed that there are exactly\r\n // 86,400,000 milliseconds per day.\"\r\n //\r\n // The fact is, that the unpredictable nature of leap seconds makes them very\r\n // difficult to work with in APIs. One can't generally pass timestamps around\r\n // that need leap seconds tables to be interpreted correctly, and expect that\r\n // one system will interpret them the same as another. For example, while your\r\n // example timestamp 1483228826 is 2017-01-01T00:00:00Z on your system,\r\n // it would be interpreted as 2017-01-01T00:00:26Z on POSIX based systems,\r\n // or systems without leap second tables. So they aren't portable.\r\n // Even on systems that have full updated tables, there's no telling what those\r\n // tables will contain in the future (beyond the 6-month IERS announcement period),\r\n // so I can't produce a future timestamp without risk that it may eventually change.\r\n //\r\n // To be clear - to support leap seconds in a programming language, the implementation\r\n // must go out of its way to do so, and must make tradeoffs that are not always acceptable.\r\n // Though there are exceptions, the general position is to not support them - not because\r\n // of any subversion or active countermeasures, but because supporting them properly is much,\r\n // much harder.\"\r\n //\r\n // https://en.wikipedia.org/wiki/Unix_time#Leap_seconds\r\n // https://en.wikipedia.org/wiki/Leap_year\r\n // https://en.wikipedia.org/wiki/Leap_second\r\n //\r\n const hour = 60 * 60 * 1000\r\n\r\n return new Date(Math.round((excelSerialDate - daysBeforeUnixEpoch) * 24 * hour))\r\n}"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,cAAcA,CAACC,eAAe,EAAEC,OAAO,EAAE;EAC/D;EACA,IAAIA,OAAO,IAAIA,OAAO,CAACC,SAAS,EAAE;IAChCF,eAAe,IAAI,IAAI;EACzB;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAMG,mBAAmB,GAAG,EAAE,GAAG,GAAG,GAAG,EAAE;;EAEzC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,IAAMC,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;EAE3B,OAAO,IAAIC,IAAI,CAACC,IAAI,CAACC,KAAK,CAAC,CAACP,eAAe,GAAGG,mBAAmB,IAAI,EAAE,GAAGC,IAAI,CAAC,CAAC;AAClF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseDate.test.js","names":["parseDate","describe","it","date","convertToUTCTimezone","Date","getTime","should","equal","getTimezoneOffset"],"sources":["../../source/read/parseDate.test.js"],"sourcesContent":["import parseDate from './parseDate.js'\r\n\r\ndescribe('parseDate', () => {\r\n\tit('should parse Excel \"serial\" dates', () => {\r\n\t\tconst date = convertToUTCTimezone(new Date(2018, 3 - 1, 24))\r\n // Excel stores dates as integers.\r\n // E.g. '24/03/2018' === 43183\r\n\t\tparseDate(43183).getTime().should.equal(date.getTime())\r\n\t})\r\n})\r\n\r\n// Converts timezone to UTC while preserving the same time\r\nfunction convertToUTCTimezone(date) {\r\n\t// Doesn't account for leap seconds but I guess that's ok\r\n\t// given that javascript's own `Date()` does not either.\r\n\t// https://www.timeanddate.com/time/leap-seconds-background.html\r\n\t//\r\n\t// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset\r\n\t//\r\n\treturn new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000)\r\n}\r\n"],"mappings":"AAAA,OAAOA,
|
|
1
|
+
{"version":3,"file":"parseDate.test.js","names":["parseDate","describe","it","date","convertToUTCTimezone","Date","getTime","should","equal","getTimezoneOffset"],"sources":["../../source/read/parseDate.test.js"],"sourcesContent":["import parseDate from './parseDate.js'\r\n\r\ndescribe('parseDate', () => {\r\n\tit('should parse Excel \"serial\" dates', () => {\r\n\t\tconst date = convertToUTCTimezone(new Date(2018, 3 - 1, 24))\r\n // Excel stores dates as integers.\r\n // E.g. '24/03/2018' === 43183\r\n\t\tparseDate(43183).getTime().should.equal(date.getTime())\r\n\t})\r\n})\r\n\r\n// Converts timezone to UTC while preserving the same time\r\nfunction convertToUTCTimezone(date) {\r\n\t// Doesn't account for leap seconds but I guess that's ok\r\n\t// given that javascript's own `Date()` does not either.\r\n\t// https://www.timeanddate.com/time/leap-seconds-background.html\r\n\t//\r\n\t// https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset\r\n\t//\r\n\treturn new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000)\r\n}\r\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,gBAAgB;AAEtCC,QAAQ,CAAC,WAAW,EAAE,YAAM;EAC3BC,EAAE,CAAC,mCAAmC,EAAE,YAAM;IAC7C,IAAMC,IAAI,GAAGC,oBAAoB,CAAC,IAAIC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC;IAC1D;IACA;IACFL,SAAS,CAAC,KAAK,CAAC,CAACM,OAAO,CAAC,CAAC,CAACC,MAAM,CAACC,KAAK,CAACL,IAAI,CAACG,OAAO,CAAC,CAAC,CAAC;EACxD,CAAC,CAAC;AACH,CAAC,CAAC;;AAEF;AACA,SAASF,oBAAoBA,CAACD,IAAI,EAAE;EACnC;EACA;EACA;EACA;EACA;EACA;EACA,OAAO,IAAIE,IAAI,CAACF,IAAI,CAACG,OAAO,CAAC,CAAC,GAAGH,IAAI,CAACM,iBAAiB,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AACvE"}
|
|
@@ -1,44 +1,36 @@
|
|
|
1
1
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
-
|
|
3
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."); }
|
|
4
|
-
|
|
5
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); }
|
|
6
|
-
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
-
|
|
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; } }
|
|
11
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
|
|
13
7
|
import { parseCellCoordinates } from './coordinates.js';
|
|
14
|
-
import { getDimensions } from '../xml/xlsx.js';
|
|
15
|
-
// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1
|
|
8
|
+
import { getDimensions } from '../xml/xlsx.js';
|
|
16
9
|
|
|
10
|
+
// `dimensions` defines the spreadsheet area containing all non-empty cells.
|
|
11
|
+
// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1
|
|
17
12
|
export default function parseDimensions(sheet) {
|
|
18
13
|
var dimensions = getDimensions(sheet);
|
|
19
|
-
|
|
20
14
|
if (dimensions) {
|
|
21
15
|
dimensions = dimensions.split(':').map(parseCellCoordinates).map(function (_ref) {
|
|
22
16
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
row = _ref2[0],
|
|
18
|
+
column = _ref2[1];
|
|
26
19
|
return {
|
|
27
20
|
row: row,
|
|
28
21
|
column: column
|
|
29
22
|
};
|
|
30
|
-
});
|
|
23
|
+
});
|
|
24
|
+
// Sometimes there can be just a single cell as a spreadsheet's "dimensions".
|
|
31
25
|
// For example, the default "dimensions" in Apache POI library is "A1",
|
|
32
26
|
// meaning that only the first cell in the spreadsheet is used.
|
|
33
27
|
//
|
|
34
28
|
// A quote from Apache POI library:
|
|
35
29
|
// "Single cell ranges are formatted like single cell references (e.g. 'A1' instead of 'A1:A1')."
|
|
36
30
|
//
|
|
37
|
-
|
|
38
31
|
if (dimensions.length === 1) {
|
|
39
32
|
dimensions = [dimensions[0], dimensions[0]];
|
|
40
33
|
}
|
|
41
|
-
|
|
42
34
|
return dimensions;
|
|
43
35
|
}
|
|
44
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseDimensions.js","names":["parseCellCoordinates","getDimensions","parseDimensions","sheet","dimensions","split","map","row","column","length"],"sources":["../../source/read/parseDimensions.js"],"sourcesContent":["import {\r\n parseCellCoordinates\r\n} from './coordinates.js'\r\n\r\nimport {\r\n getDimensions\r\n} from '../xml/xlsx.js'\r\n\r\n// `dimensions` defines the spreadsheet area containing all non-empty cells.\r\n// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1\r\nexport default function parseDimensions(sheet) {\r\n let dimensions = getDimensions(sheet)\r\n if (dimensions) {\r\n dimensions = dimensions.split(':').map(parseCellCoordinates).map(([row, column]) => ({\r\n row,\r\n 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 }\r\n}\r\n\r\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"parseDimensions.js","names":["parseCellCoordinates","getDimensions","parseDimensions","sheet","dimensions","split","map","_ref","_ref2","_slicedToArray","row","column","length"],"sources":["../../source/read/parseDimensions.js"],"sourcesContent":["import {\r\n parseCellCoordinates\r\n} from './coordinates.js'\r\n\r\nimport {\r\n getDimensions\r\n} from '../xml/xlsx.js'\r\n\r\n// `dimensions` defines the spreadsheet area containing all non-empty cells.\r\n// https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.spreadsheet.sheetdimension?view=openxml-2.8.1\r\nexport default function parseDimensions(sheet) {\r\n let dimensions = getDimensions(sheet)\r\n if (dimensions) {\r\n dimensions = dimensions.split(':').map(parseCellCoordinates).map(([row, column]) => ({\r\n row,\r\n 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 }\r\n}\r\n\r\n"],"mappings":";;;;;;AAAA,SACEA,oBAAoB,QACf,kBAAkB;AAEzB,SACEC,aAAa,QACR,gBAAgB;;AAEvB;AACA;AACA,eAAe,SAASC,eAAeA,CAACC,KAAK,EAAE;EAC7C,IAAIC,UAAU,GAAGH,aAAa,CAACE,KAAK,CAAC;EACrC,IAAIC,UAAU,EAAE;IACdA,UAAU,GAAGA,UAAU,CAACC,KAAK,CAAC,GAAG,CAAC,CAACC,GAAG,CAACN,oBAAoB,CAAC,CAACM,GAAG,CAAC,UAAAC,IAAA;MAAA,IAAAC,KAAA,GAAAC,cAAA,CAAAF,IAAA;QAAEG,GAAG,GAAAF,KAAA;QAAEG,MAAM,GAAAH,KAAA;MAAA,OAAO;QACnFE,GAAG,EAAHA,GAAG;QACHC,MAAM,EAANA;MACF,CAAC;IAAA,CAAC,CAAC;IACH;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAIP,UAAU,CAACQ,MAAM,KAAK,CAAC,EAAE;MAC3BR,UAAU,GAAG,CAACA,UAAU,CAAC,CAAC,CAAC,EAAEA,UAAU,CAAC,CAAC,CAAC,CAAC;IAC7C;IACA,OAAOA,UAAU;EACnB;AACF"}
|