@fileverse-dev/formulajs 4.4.20-mod-2 → 4.4.20-mod-3

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.
@@ -1,4 +1,4 @@
1
- /* @fileverse-dev/formulajs v4.4.20-mod-2 */
1
+ /* @fileverse-dev/formulajs v4.4.20-mod-3 */
2
2
  var _excluded = [ "confirmations", "dataDecoded" ];
3
3
 
4
4
  function _objectWithoutProperties(e, t) {
@@ -4963,10 +4963,6 @@ function _typeof(o) {
4963
4963
  return result;
4964
4964
  }
4965
4965
  function XLOOKUP(search_key, lookup_range, result_range, missing_value, isCol, match_mode, search_mode) {
4966
- var ERROR_NA = "#N/A";
4967
- var ERROR_REF = "#REF!";
4968
- var ERROR_VALUE = "#VALUE!";
4969
- var ERROR_NUM = "#NUM!";
4970
4966
  console.log("XLOOKUP parameters:", {
4971
4967
  search_key: search_key,
4972
4968
  lookup_range: lookup_range,
@@ -4978,44 +4974,53 @@ function _typeof(o) {
4978
4974
  });
4979
4975
  if (search_key === undefined || search_key === null) {
4980
4976
  console.log("Error: search_key is required");
4981
- return ERROR_VALUE;
4977
+ return new Error("Error: search_key is required");
4982
4978
  }
4983
4979
  if (!lookup_range || !result_range) {
4984
4980
  console.log("Error: lookup_range and result_range are required");
4985
- return ERROR_REF;
4981
+ return new Error("Error: lookup_range and result_range are required");
4986
4982
  }
4987
4983
  var lookup_array = normalizeLookupRange(lookup_range);
4988
4984
  if (!lookup_array) {
4989
4985
  console.log("Error: lookup_range must be a singular row or column");
4990
- return ERROR_REF;
4986
+ return new Error("Error: lookup_range must be a singular row or column");
4991
4987
  }
4992
4988
  var result_array = normalizeResultRange(result_range);
4993
4989
  if (!result_array) {
4994
4990
  console.log("Error: Invalid result_range");
4995
- return ERROR_REF;
4991
+ return new Error("Error: Invalid result_range");
4996
4992
  }
4997
- result_array.length === 1;
4998
- missing_value = missing_value !== undefined ? missing_value : ERROR_NA;
4993
+ result_array.map((function(row) {
4994
+ if (row.length !== lookup_array.length) {
4995
+ console.log("Error: lookup_range and result_range must have the same number of columns");
4996
+ return new Error("Error: lookup_range and result_range must have the same number of columns/rows");
4997
+ }
4998
+ }));
4999
+ missing_value = missing_value !== undefined ? missing_value : new Error("Error: Didn't find value in XLOOKUP evaluation");
4999
5000
  match_mode = match_mode !== undefined ? match_mode : 0;
5000
5001
  search_mode = search_mode !== undefined ? search_mode : 1;
5001
5002
  isCol = isCol !== undefined ? isCol : false;
5002
5003
  if (![ 0, 1, -1, 2 ].includes(match_mode)) {
5003
5004
  console.log("Error: match_mode must be 0, 1, -1, or 2");
5004
- return ERROR_NUM;
5005
+ return new Error("Error: match_mode must be 0, 1, -1, or 2");
5005
5006
  }
5006
5007
  if (![ 1, -1, 2, -2 ].includes(search_mode)) {
5007
5008
  console.log("Error: search_mode must be 1, -1, 2, or -2");
5008
- return ERROR_NUM;
5009
+ return new Error("Error: search_mode must be 1, -1, 2, or -2");
5009
5010
  }
5010
5011
  if (Math.abs(search_mode) === 2 && match_mode === 2) {
5011
5012
  console.log("Error: Binary search (search_mode ±2) cannot be used with wildcard matching (match_mode 2)");
5012
- return ERROR_VALUE;
5013
+ return new Error("Error: Binary search (search_mode ±2) cannot be used with wildcard matching (match_mode 2)");
5013
5014
  }
5014
5015
  console.log("Normalized arrays:", {
5015
5016
  lookup_array: lookup_array,
5016
5017
  result_array: result_array
5017
5018
  });
5018
- return performLookup(search_key, lookup_array, result_array, missing_value, match_mode, search_mode, isCol);
5019
+ var res = performLookup(search_key, lookup_array, result_array, missing_value, match_mode, search_mode, isCol);
5020
+ res = isCol ? Array.isArray(res) ? res.map((function(item) {
5021
+ return [ item.toString() ];
5022
+ })) : res : res;
5023
+ return res;
5019
5024
  }
5020
5025
  function normalizeLookupRange(lookup_range) {
5021
5026
  if (!Array.isArray(lookup_range)) {
@@ -5058,6 +5063,7 @@ function _typeof(o) {
5058
5063
  isCol: isCol
5059
5064
  });
5060
5065
  var foundIndex = -1;
5066
+ var isSingleResultRow = result_array.length === 1;
5061
5067
  switch (match_mode) {
5062
5068
  case 0:
5063
5069
  foundIndex = findExactMatch(search_key, lookup_array, search_mode);
@@ -5076,26 +5082,23 @@ function _typeof(o) {
5076
5082
  break;
5077
5083
  }
5078
5084
  if (foundIndex === -1) {
5079
- if (result_array[0].length > 1) {
5080
- var errorArray = new Array(result_array[0].length).fill(missing_value);
5081
- if (isCol) {
5082
- return errorArray.map((function(val) {
5083
- return [ val ];
5084
- }));
5085
- } else {
5086
- return errorArray;
5087
- }
5085
+ return missing_value;
5086
+ }
5087
+ if (isSingleResultRow) {
5088
+ var resultRow = result_array[0];
5089
+ if (isCol) {
5090
+ return resultRow.map((function(val) {
5091
+ return [ val ];
5092
+ }));
5088
5093
  } else {
5089
- return missing_value;
5094
+ return resultRow;
5090
5095
  }
5091
- }
5092
- if (result_array[0].length === 1) {
5093
- return result_array[foundIndex][0];
5094
5096
  } else {
5095
5097
  if (isCol) {
5096
- return result_array[foundIndex].map((function(val) {
5097
- return [ val ];
5098
+ var columnValues = result_array.map((function(row) {
5099
+ return row[foundIndex];
5098
5100
  }));
5101
+ return columnValues;
5099
5102
  } else {
5100
5103
  return result_array[foundIndex];
5101
5104
  }