@fileverse-dev/formulajs 4.4.49 → 4.4.50

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/cjs/index.cjs CHANGED
@@ -1442,6 +1442,9 @@ function VLOOKUP(lookup_value, table_array, col_index_num, range_lookup) {
1442
1442
  return result
1443
1443
  }
1444
1444
 
1445
+ /**
1446
+ * @param isColV When "true", returns the matched column (value at match index from each row of result_range). When false/omitted, returns the matched row (one row from result_range).
1447
+ */
1445
1448
  function XLOOKUP(search_key, lookup_range, result_range, isColV, missing_value,match_mode, search_mode) {
1446
1449
  let isCol = isColV === "true" ? true : false;
1447
1450
 
@@ -1478,29 +1481,35 @@ result_array.map((row) => {
1478
1481
  });
1479
1482
 
1480
1483
  // Set default parameter values Error: Didn't find value in XLOOKUP evaluation
1481
- missing_value = missing_value !== undefined ? missing_value : new Error("not_found");
1484
+ missing_value = missing_value !== undefined ? missing_value : new Error(`Did not find value ${search_key} in XLOOKUP evaluation.`);
1482
1485
  match_mode = match_mode !== undefined ? match_mode : 0;
1483
1486
  search_mode = search_mode !== undefined ? search_mode : 1;
1484
1487
  isCol = isCol !== undefined ? isCol : false;
1485
-
1488
+
1486
1489
  // Validate match_mode
1487
1490
  if (![0, 1, -1, 2].includes(match_mode)) {
1488
1491
  return new Error('match_mode_must')
1489
1492
  }
1490
-
1493
+
1491
1494
  // Validate search_mode
1492
1495
  if (![1, -1, 2, -2].includes(search_mode)) {
1493
1496
  return new Error('search_mode_must')
1494
1497
  }
1495
-
1498
+
1496
1499
  // Validate binary search requirements
1497
1500
  if (Math.abs(search_mode) === 2 && match_mode === 2) {
1498
1501
  return new Error('binary_search_and_wildcard')
1499
1502
  }
1500
-
1501
- let res = performLookup(search_key, lookup_array, result_array, missing_value, match_mode, search_mode, isCol);
1502
- res = isCol ? Array.isArray(res)?res.map((item) => [item.toString()]):res : [res];
1503
- return res
1503
+
1504
+ const res = performLookup(search_key, lookup_array, result_array, missing_value, match_mode, search_mode, isCol);
1505
+ // If not found (or missing_value), return the error/value as-is — do not wrap in array
1506
+ if (res instanceof Error) {
1507
+ return res
1508
+ }
1509
+ // isCol: return column at match index from each row (array of single-cell arrays). Else: return matched row as single row array.
1510
+ return isCol
1511
+ ? (Array.isArray(res) ? res.map((item) => [item.toString()]) : res)
1512
+ : [res]
1504
1513
  }
1505
1514
 
1506
1515
  function normalizeLookupRange(lookup_range) {
package/lib/esm/index.mjs CHANGED
@@ -1440,6 +1440,9 @@ function VLOOKUP(lookup_value, table_array, col_index_num, range_lookup) {
1440
1440
  return result
1441
1441
  }
1442
1442
 
1443
+ /**
1444
+ * @param isColV When "true", returns the matched column (value at match index from each row of result_range). When false/omitted, returns the matched row (one row from result_range).
1445
+ */
1443
1446
  function XLOOKUP(search_key, lookup_range, result_range, isColV, missing_value,match_mode, search_mode) {
1444
1447
  let isCol = isColV === "true" ? true : false;
1445
1448
 
@@ -1476,29 +1479,35 @@ result_array.map((row) => {
1476
1479
  });
1477
1480
 
1478
1481
  // Set default parameter values Error: Didn't find value in XLOOKUP evaluation
1479
- missing_value = missing_value !== undefined ? missing_value : new Error("not_found");
1482
+ missing_value = missing_value !== undefined ? missing_value : new Error(`Did not find value ${search_key} in XLOOKUP evaluation.`);
1480
1483
  match_mode = match_mode !== undefined ? match_mode : 0;
1481
1484
  search_mode = search_mode !== undefined ? search_mode : 1;
1482
1485
  isCol = isCol !== undefined ? isCol : false;
1483
-
1486
+
1484
1487
  // Validate match_mode
1485
1488
  if (![0, 1, -1, 2].includes(match_mode)) {
1486
1489
  return new Error('match_mode_must')
1487
1490
  }
1488
-
1491
+
1489
1492
  // Validate search_mode
1490
1493
  if (![1, -1, 2, -2].includes(search_mode)) {
1491
1494
  return new Error('search_mode_must')
1492
1495
  }
1493
-
1496
+
1494
1497
  // Validate binary search requirements
1495
1498
  if (Math.abs(search_mode) === 2 && match_mode === 2) {
1496
1499
  return new Error('binary_search_and_wildcard')
1497
1500
  }
1498
-
1499
- let res = performLookup(search_key, lookup_array, result_array, missing_value, match_mode, search_mode, isCol);
1500
- res = isCol ? Array.isArray(res)?res.map((item) => [item.toString()]):res : [res];
1501
- return res
1501
+
1502
+ const res = performLookup(search_key, lookup_array, result_array, missing_value, match_mode, search_mode, isCol);
1503
+ // If not found (or missing_value), return the error/value as-is — do not wrap in array
1504
+ if (res instanceof Error) {
1505
+ return res
1506
+ }
1507
+ // isCol: return column at match index from each row (array of single-cell arrays). Else: return matched row as single row array.
1508
+ return isCol
1509
+ ? (Array.isArray(res) ? res.map((item) => [item.toString()]) : res)
1510
+ : [res]
1502
1511
  }
1503
1512
 
1504
1513
  function normalizeLookupRange(lookup_range) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/formulajs",
3
- "version": "4.4.49",
3
+ "version": "4.4.50",
4
4
  "description": "JavaScript implementation of most Microsoft Excel formula functions",
5
5
  "author": "Formulajs",
6
6
  "publishConfig": {
@@ -4555,6 +4555,9 @@ declare function WORKDAY_INTL(start_date: any, days: any, weekend: any, holidays
4555
4555
  * @returns
4556
4556
  */
4557
4557
  declare function XIRR(values: any, dates: any, guess: any): any;
4558
+ /**
4559
+ * @param isColV When "true", returns the matched column (value at match index from each row of result_range). When false/omitted, returns the matched row (one row from result_range).
4560
+ */
4558
4561
  declare function XLOOKUP(search_key: any, lookup_range: any, result_range: any, isColV: any, missing_value: any, match_mode: any, search_mode: any): any;
4559
4562
  /**
4560
4563
  * Returns the net present value for a schedule of cash flows that is not necessarily periodic.
@@ -4494,6 +4494,9 @@ export function WORKDAY_INTL(start_date: any, days: any, weekend: any, holidays:
4494
4494
  * @returns
4495
4495
  */
4496
4496
  export function XIRR(values: any, dates: any, guess: any): any;
4497
+ /**
4498
+ * @param isColV When "true", returns the matched column (value at match index from each row of result_range). When false/omitted, returns the matched row (one row from result_range).
4499
+ */
4497
4500
  export function XLOOKUP(search_key: any, lookup_range: any, result_range: any, isColV: any, missing_value: any, match_mode: any, search_mode: any): any;
4498
4501
  /**
4499
4502
  * Returns the net present value for a schedule of cash flows that is not necessarily periodic.