@fileverse-dev/formulajs 4.4.19 → 4.4.20-mod-1
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 +98 -2
- package/lib/browser/formula.min.js +2 -2
- package/lib/browser/formula.min.js.map +1 -1
- package/lib/cjs/index.cjs +113 -1
- package/lib/esm/index.mjs +113 -2
- package/package.json +1 -1
- package/types/cjs/index.d.cts +1 -0
- package/types/esm/index.d.mts +1 -0
package/lib/browser/formula.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* @fileverse-dev/formulajs v4.4.
|
|
1
|
+
/* @fileverse-dev/formulajs v4.4.20-mod-1 */
|
|
2
2
|
var _excluded = [ "confirmations", "dataDecoded" ];
|
|
3
3
|
|
|
4
4
|
function _objectWithoutProperties(e, t) {
|
|
@@ -4863,7 +4863,7 @@ function _typeof(o) {
|
|
|
4863
4863
|
var sortColumnIndex = parseNumber(sortIndex);
|
|
4864
4864
|
if (!sortColumnIndex || sortColumnIndex < 1) return value;
|
|
4865
4865
|
sortColumnIndex = sortColumnIndex - 1;
|
|
4866
|
-
var sortDirection = isAscending.toLowerCase() === "false" ? -1 : 1;
|
|
4866
|
+
var sortDirection = (isAscending === null || isAscending === void 0 ? void 0 : isAscending.toLowerCase()) === "false" ? -1 : 1;
|
|
4867
4867
|
var parsedSortDirection = parseNumber(sortDirection);
|
|
4868
4868
|
if (parsedSortDirection !== 1 && parsedSortDirection !== -1) return value;
|
|
4869
4869
|
var isSortByColumn = parseBool(sortByColumn);
|
|
@@ -4962,6 +4962,101 @@ function _typeof(o) {
|
|
|
4962
4962
|
}
|
|
4963
4963
|
return result;
|
|
4964
4964
|
}
|
|
4965
|
+
function XLOOKUP(lookup_value, lookup_array, return_array, if_not_found, match_mode, search_mode) {
|
|
4966
|
+
var ERROR_NA = "#N/A";
|
|
4967
|
+
var ERROR_REF = "#REF!";
|
|
4968
|
+
console.log("XLOOKUP parameters:", {
|
|
4969
|
+
lookup_value: lookup_value,
|
|
4970
|
+
lookup_array: lookup_array,
|
|
4971
|
+
return_array: return_array,
|
|
4972
|
+
if_not_found: if_not_found,
|
|
4973
|
+
match_mode: match_mode,
|
|
4974
|
+
search_mode: search_mode
|
|
4975
|
+
});
|
|
4976
|
+
console.log("XLOOKUP called with:", {
|
|
4977
|
+
lookup_value: lookup_value,
|
|
4978
|
+
lookup_array: lookup_array,
|
|
4979
|
+
return_array: return_array,
|
|
4980
|
+
if_not_found: if_not_found,
|
|
4981
|
+
match_mode: match_mode,
|
|
4982
|
+
search_mode: search_mode
|
|
4983
|
+
});
|
|
4984
|
+
if (typeof return_array === "number" && Array.isArray(lookup_array) && Array.isArray(lookup_array[0])) {
|
|
4985
|
+
console.log("Detected VLOOKUP-style call");
|
|
4986
|
+
var table_array = lookup_array;
|
|
4987
|
+
var col_index_num = return_array;
|
|
4988
|
+
var range_lookup = !(if_not_found === "false" || if_not_found === false || if_not_found === 0);
|
|
4989
|
+
if (col_index_num < 1 || col_index_num > table_array[0].length) {
|
|
4990
|
+
return ERROR_REF;
|
|
4991
|
+
}
|
|
4992
|
+
var _lookup_col = table_array.map((function(row) {
|
|
4993
|
+
return row[0];
|
|
4994
|
+
}));
|
|
4995
|
+
var _return_col = table_array.map((function(row) {
|
|
4996
|
+
return row[col_index_num - 1];
|
|
4997
|
+
}));
|
|
4998
|
+
return performLookup(lookup_value, _lookup_col, _return_col, ERROR_NA, range_lookup ? -1 : 0);
|
|
4999
|
+
}
|
|
5000
|
+
console.log("Detected standard XLOOKUP call");
|
|
5001
|
+
if (!lookup_array || !return_array) {
|
|
5002
|
+
console.log("Missing lookup_array or return_array");
|
|
5003
|
+
return ERROR_NA;
|
|
5004
|
+
}
|
|
5005
|
+
var lookup_col = lookup_array;
|
|
5006
|
+
var return_col = return_array;
|
|
5007
|
+
if (Array.isArray(lookup_array) && Array.isArray(lookup_array[0])) {
|
|
5008
|
+
lookup_col = lookup_array.map((function(row) {
|
|
5009
|
+
return row[0];
|
|
5010
|
+
}));
|
|
5011
|
+
console.log("Extracted lookup column from 2D array:", lookup_col);
|
|
5012
|
+
}
|
|
5013
|
+
if (Array.isArray(return_array) && Array.isArray(return_array[0])) {
|
|
5014
|
+
return_col = return_array.map((function(row) {
|
|
5015
|
+
return row[0];
|
|
5016
|
+
}));
|
|
5017
|
+
console.log("Extracted return column from 2D array:", return_col);
|
|
5018
|
+
}
|
|
5019
|
+
if (lookup_col.length !== return_col.length) {
|
|
5020
|
+
console.log("Array length mismatch:", lookup_col.length, "vs", return_col.length);
|
|
5021
|
+
return ERROR_NA;
|
|
5022
|
+
}
|
|
5023
|
+
if_not_found = if_not_found !== undefined ? if_not_found : ERROR_NA;
|
|
5024
|
+
match_mode = match_mode || 0;
|
|
5025
|
+
search_mode = search_mode || 1;
|
|
5026
|
+
return performLookup(lookup_value, lookup_col, return_col, if_not_found, match_mode, search_mode);
|
|
5027
|
+
}
|
|
5028
|
+
function performLookup(lookup_value, lookup_array, return_array, if_not_found, match_mode, search_mode) {
|
|
5029
|
+
var isNumberLookup = typeof lookup_value === "number";
|
|
5030
|
+
var lookupValue = typeof lookup_value === "string" ? lookup_value.toLowerCase().trim() : lookup_value;
|
|
5031
|
+
var bestMatchIndex = -1;
|
|
5032
|
+
console.log("XLOOKUP Debug:", {
|
|
5033
|
+
looking_for: lookup_value,
|
|
5034
|
+
processed_lookup: lookupValue,
|
|
5035
|
+
lookup_array: lookup_array,
|
|
5036
|
+
return_array: return_array,
|
|
5037
|
+
match_mode: match_mode
|
|
5038
|
+
});
|
|
5039
|
+
var startIndex = search_mode === -1 ? lookup_array.length - 1 : 0;
|
|
5040
|
+
var endIndex = search_mode === -1 ? -1 : lookup_array.length;
|
|
5041
|
+
var step = search_mode === -1 ? -1 : 1;
|
|
5042
|
+
for (var i = startIndex; i !== endIndex; i += step) {
|
|
5043
|
+
var rawValue = lookup_array[i];
|
|
5044
|
+
var arrayValue = typeof rawValue === "string" ? rawValue.toLowerCase().trim() : rawValue;
|
|
5045
|
+
console.log('Comparing: "'.concat(lookupValue, '" === "').concat(arrayValue, '" (types: ').concat(_typeof(lookupValue), " vs ").concat(_typeof(arrayValue), ")"));
|
|
5046
|
+
if (arrayValue === lookupValue) {
|
|
5047
|
+
console.log("Found match at index ".concat(i, ": ").concat(return_array[i]));
|
|
5048
|
+
return return_array[i];
|
|
5049
|
+
}
|
|
5050
|
+
if (match_mode === -1) {
|
|
5051
|
+
if (isNumberLookup && typeof arrayValue === "number" && arrayValue <= lookup_value || !isNumberLookup && typeof arrayValue === "string" && arrayValue.localeCompare(lookupValue) <= 0) {
|
|
5052
|
+
bestMatchIndex = i;
|
|
5053
|
+
console.log("Approximate match candidate at index ".concat(i, ": ").concat(arrayValue));
|
|
5054
|
+
}
|
|
5055
|
+
}
|
|
5056
|
+
}
|
|
5057
|
+
console.log("No exact match found. Returning: ".concat(bestMatchIndex !== -1 ? return_array[bestMatchIndex] : if_not_found));
|
|
5058
|
+
return bestMatchIndex !== -1 ? return_array[bestMatchIndex] : if_not_found;
|
|
5059
|
+
}
|
|
4965
5060
|
function CHAR(number) {
|
|
4966
5061
|
number = parseNumber(number);
|
|
4967
5062
|
if (number === 0) {
|
|
@@ -19206,6 +19301,7 @@ function _typeof(o) {
|
|
|
19206
19301
|
exports.WORKDAYINTL = WORKDAYINTL;
|
|
19207
19302
|
exports.WORKDAY_INTL = WORKDAY_INTL;
|
|
19208
19303
|
exports.XIRR = XIRR;
|
|
19304
|
+
exports.XLOOKUP = XLOOKUP;
|
|
19209
19305
|
exports.XNPV = XNPV;
|
|
19210
19306
|
exports.XOR = XOR;
|
|
19211
19307
|
exports.YEAR = YEAR;
|