@rowsncolumns/fast-formula-parser 6.2.42 → 6.2.44

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/dist/cjs/index.js CHANGED
@@ -5649,6 +5649,7 @@ const FORMULA_LOCALE_DATA = {
5649
5649
  "ISNUMBER": "ESTNUM",
5650
5650
  "ISO.CEILING": "ISO.PLAFOND",
5651
5651
  "ISODD": "EST.IMPAIR",
5652
+ "ISOMITTED": "ISOMITTED",
5652
5653
  "ISOWEEKNUM": "NO.SEMAINE.ISO",
5653
5654
  "ISPMT": "ISPMT",
5654
5655
  "ISREF": "ESTREF",
@@ -25694,6 +25695,55 @@ const lookupEquals = (a, b) =>
25694
25695
  ? a.toLowerCase() === b.toLowerCase()
25695
25696
  : a === b;
25696
25697
 
25698
+ /**
25699
+ * The sheet range a lookup table argument was read from, or undefined when the table is an
25700
+ * array (an array constant, a spilled range or another function's result). The matrix the
25701
+ * host returned must fit inside that range — it is a window starting at `from` (a full-column
25702
+ * reference is trimmed to the data extent) — or no cell can be derived from a matrix index.
25703
+ */
25704
+ const rangeOf = (arg, matrix) => {
25705
+ const ref = arg?.position;
25706
+ if (!ref || ref.isSpilledRange || ref.sheetEnd != null) return undefined;
25707
+ let range;
25708
+ if (ref.from && ref.to) {
25709
+ range = ref;
25710
+ } else if (ref.row != null && ref.col != null) {
25711
+ range = {
25712
+ sheet: ref.sheet,
25713
+ from: { row: ref.row, col: ref.col },
25714
+ to: { row: ref.row, col: ref.col },
25715
+ };
25716
+ } else {
25717
+ return undefined;
25718
+ }
25719
+ const fits =
25720
+ matrix.length <= range.to.row - range.from.row + 1 &&
25721
+ (matrix[0]?.length ?? 0) <= range.to.col - range.from.col + 1;
25722
+ return fits ? range : undefined;
25723
+ };
25724
+
25725
+ /**
25726
+ * The cell VLOOKUP/HLOOKUP found. Over a sheet range it is the cell's REFERENCE (as INDEX returns
25727
+ * one), so the result carries `=B2` semantics by construction: a blank cell displays 0, is 0 in
25728
+ * arithmetic and comparison, "" in text — `=VLOOKUP(…)+0` is 0, `=VLOOKUP(…)=""` is TRUE,
25729
+ * `=VLOOKUP(…)&"x"` is "x". The engine has no blank scalar to return instead: the dispatcher reads
25730
+ * a returned `undefined` as "function not implemented" (`#NAME?`) and `null` is the skipped-argument
25731
+ * marker. Over an array there is no cell to point at, so a blank slot coerces to 0 as blank does in
25732
+ * arithmetic. A cell holding `=""` is text, not blank, and comes back as "" either way.
25733
+ */
25734
+ const matchedCell = (tableRange, tableArray, rowIdx, colIdx) => {
25735
+ if (tableRange) {
25736
+ return {
25737
+ ref: {
25738
+ sheet: tableRange.sheet,
25739
+ row: tableRange.from.row + rowIdx,
25740
+ col: tableRange.from.col + colIdx,
25741
+ },
25742
+ };
25743
+ }
25744
+ return tableArray[rowIdx][colIdx] ?? 0;
25745
+ };
25746
+
25697
25747
  /**
25698
25748
  * Exact-mode match for VLOOKUP/HLOOKUP/XLOOKUP/XMATCH: wildcards when the lookup text has
25699
25749
  * them, otherwise case-insensitive equality.
@@ -25960,6 +26010,7 @@ const ReferenceFunctions = {
25960
26010
  HLOOKUP: (lookupValue, tableArray, rowIndexNum, rangeLookup) => {
25961
26011
  // preserve type of lookupValue
25962
26012
  lookupValue = H$2.accept(lookupValue);
26013
+ const tableArg = tableArray;
25963
26014
  try {
25964
26015
  tableArray = H$2.accept(tableArray, Types.ARRAY, undefined, false);
25965
26016
  } catch (e) {
@@ -25971,6 +26022,7 @@ const ReferenceFunctions = {
25971
26022
  }
25972
26023
  throw e;
25973
26024
  }
26025
+ const tableRange = rangeOf(tableArg, tableArray);
25974
26026
  rowIndexNum = H$2.accept(rowIndexNum, Types.NUMBER);
25975
26027
  rangeLookup = H$2.accept(rangeLookup, Types.BOOLEAN, true);
25976
26028
 
@@ -25983,7 +26035,7 @@ const ReferenceFunctions = {
25983
26035
  if (rangeLookup) {
25984
26036
  const index = approximateMatchIndex(tableArray[0], lookupValue);
25985
26037
  if (index === -1) throw FormulaError.NA;
25986
- return tableArray[rowIndexNum - 1][index];
26038
+ return matchedCell(tableRange, tableArray, rowIndexNum - 1, index);
25987
26039
  }
25988
26040
  // exact lookup: case-insensitive, with wildcard support
25989
26041
  else {
@@ -25992,7 +26044,7 @@ const ReferenceFunctions = {
25992
26044
  );
25993
26045
  // the exact match is not found
25994
26046
  if (index === -1) throw FormulaError.NA;
25995
- return tableArray[rowIndexNum - 1][index];
26047
+ return matchedCell(tableRange, tableArray, rowIndexNum - 1, index);
25996
26048
  }
25997
26049
  },
25998
26050
 
@@ -26496,6 +26548,7 @@ const ReferenceFunctions = {
26496
26548
  VLOOKUP: (lookupValue, tableArray, colIndexNum, rangeLookup) => {
26497
26549
  // preserve type of lookupValue
26498
26550
  lookupValue = H$2.accept(lookupValue);
26551
+ const tableArg = tableArray;
26499
26552
  try {
26500
26553
  tableArray = H$2.accept(tableArray, Types.ARRAY, undefined, false);
26501
26554
  } catch (e) {
@@ -26507,6 +26560,7 @@ const ReferenceFunctions = {
26507
26560
  }
26508
26561
  throw e;
26509
26562
  }
26563
+ const tableRange = rangeOf(tableArg, tableArray);
26510
26564
  colIndexNum = H$2.accept(colIndexNum, Types.NUMBER);
26511
26565
  rangeLookup = H$2.accept(rangeLookup, Types.BOOLEAN, true);
26512
26566
 
@@ -26522,7 +26576,7 @@ const ReferenceFunctions = {
26522
26576
  lookupValue,
26523
26577
  );
26524
26578
  if (index === -1) throw FormulaError.NA;
26525
- return tableArray[index][colIndexNum - 1] ?? "";
26579
+ return matchedCell(tableRange, tableArray, index, colIndexNum - 1);
26526
26580
  }
26527
26581
  // exact lookup: case-insensitive, with wildcard support
26528
26582
  else {
@@ -26531,7 +26585,7 @@ const ReferenceFunctions = {
26531
26585
  );
26532
26586
  // the exact match is not found
26533
26587
  if (index === -1) throw FormulaError.NA;
26534
- return tableArray[index][colIndexNum - 1] ?? "";
26588
+ return matchedCell(tableRange, tableArray, index, colIndexNum - 1);
26535
26589
  }
26536
26590
  },
26537
26591