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