@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/cjs/index.cjs
CHANGED
|
@@ -1441,51 +1441,47 @@ function VLOOKUP(lookup_value, table_array, col_index_num, range_lookup) {
|
|
|
1441
1441
|
return result
|
|
1442
1442
|
}
|
|
1443
1443
|
|
|
1444
|
-
function XLOOKUP(search_key, lookup_range, result_range, missing_value,
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
const ERROR_VALUE = '#VALUE!';
|
|
1449
|
-
const ERROR_NUM = '#NUM!';
|
|
1450
|
-
|
|
1451
|
-
console.log('XLOOKUP parameters:', { search_key, lookup_range, result_range, missing_value, match_mode, search_mode, isCol });
|
|
1444
|
+
function XLOOKUP(search_key, lookup_range, result_range, missing_value, isColV,match_mode, search_mode) {
|
|
1445
|
+
let isCol = isColV === "true" ? true : false;
|
|
1446
|
+
|
|
1447
|
+
console.log('XLOOKUP parameters:', { search_key, lookup_range, result_range, missing_value, match_mode, search_mode, isCol });
|
|
1452
1448
|
|
|
1453
1449
|
// Validate required parameters
|
|
1454
1450
|
if (search_key === undefined || search_key === null) {
|
|
1455
1451
|
console.log('Error: search_key is required');
|
|
1456
|
-
return
|
|
1452
|
+
return new Error('Error: search_key is required')
|
|
1457
1453
|
}
|
|
1458
1454
|
|
|
1459
1455
|
if (!lookup_range || !result_range) {
|
|
1460
1456
|
console.log('Error: lookup_range and result_range are required');
|
|
1461
|
-
return
|
|
1457
|
+
return new Error('Error: lookup_range and result_range are required')
|
|
1462
1458
|
}
|
|
1463
1459
|
|
|
1464
1460
|
// Validate and normalize lookup_range (must be singular row or column)
|
|
1465
1461
|
let lookup_array = normalizeLookupRange(lookup_range);
|
|
1466
1462
|
if (!lookup_array) {
|
|
1467
1463
|
console.log('Error: lookup_range must be a singular row or column');
|
|
1468
|
-
return
|
|
1464
|
+
return new Error('Error: lookup_range must be a singular row or column')
|
|
1469
1465
|
}
|
|
1470
1466
|
|
|
1471
1467
|
// Validate and normalize result_range
|
|
1472
1468
|
let result_array = normalizeResultRange(result_range);
|
|
1473
1469
|
if (!result_array) {
|
|
1474
1470
|
console.log('Error: Invalid result_range');
|
|
1475
|
-
return
|
|
1471
|
+
return new Error('Error: Invalid result_range')
|
|
1476
1472
|
}
|
|
1477
1473
|
|
|
1478
1474
|
// Validate that lookup and result ranges have compatible dimensions
|
|
1479
|
-
// Exception: if result_range is a single row, it can be returned regardless of lookup_range length
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1475
|
+
// Exception: if result_range is a single row, it can be returned regardless of lookup_range length
|
|
1476
|
+
result_array.map((row) => {
|
|
1477
|
+
if (row.length !== lookup_array.length) {
|
|
1478
|
+
console.log('Error: lookup_range and result_range must have the same number of columns');
|
|
1479
|
+
return new Error('Error: lookup_range and result_range must have the same number of columns/rows')
|
|
1480
|
+
}
|
|
1481
|
+
});
|
|
1486
1482
|
|
|
1487
1483
|
// Set default parameter values
|
|
1488
|
-
missing_value = missing_value !== undefined ? missing_value :
|
|
1484
|
+
missing_value = missing_value !== undefined ? missing_value : new Error("Error: Didn't find value in XLOOKUP evaluation");
|
|
1489
1485
|
match_mode = match_mode !== undefined ? match_mode : 0;
|
|
1490
1486
|
search_mode = search_mode !== undefined ? search_mode : 1;
|
|
1491
1487
|
isCol = isCol !== undefined ? isCol : false;
|
|
@@ -1493,24 +1489,26 @@ function XLOOKUP(search_key, lookup_range, result_range, missing_value, isCol,ma
|
|
|
1493
1489
|
// Validate match_mode
|
|
1494
1490
|
if (![0, 1, -1, 2].includes(match_mode)) {
|
|
1495
1491
|
console.log('Error: match_mode must be 0, 1, -1, or 2');
|
|
1496
|
-
return
|
|
1492
|
+
return new Error('Error: match_mode must be 0, 1, -1, or 2')
|
|
1497
1493
|
}
|
|
1498
1494
|
|
|
1499
1495
|
// Validate search_mode
|
|
1500
1496
|
if (![1, -1, 2, -2].includes(search_mode)) {
|
|
1501
1497
|
console.log('Error: search_mode must be 1, -1, 2, or -2');
|
|
1502
|
-
return
|
|
1498
|
+
return new Error('Error: search_mode must be 1, -1, 2, or -2')
|
|
1503
1499
|
}
|
|
1504
1500
|
|
|
1505
1501
|
// Validate binary search requirements
|
|
1506
1502
|
if (Math.abs(search_mode) === 2 && match_mode === 2) {
|
|
1507
1503
|
console.log('Error: Binary search (search_mode ±2) cannot be used with wildcard matching (match_mode 2)');
|
|
1508
|
-
return
|
|
1504
|
+
return new Error('Error: Binary search (search_mode ±2) cannot be used with wildcard matching (match_mode 2)')
|
|
1509
1505
|
}
|
|
1510
1506
|
|
|
1511
1507
|
console.log('Normalized arrays:', { lookup_array, result_array });
|
|
1512
1508
|
|
|
1513
|
-
|
|
1509
|
+
let res = performLookup(search_key, lookup_array, result_array, missing_value, match_mode, search_mode, isCol);
|
|
1510
|
+
res = isCol ? Array.isArray(res)?res.map((item) => [item.toString()]):res : res;
|
|
1511
|
+
return res
|
|
1514
1512
|
}
|
|
1515
1513
|
|
|
1516
1514
|
function normalizeLookupRange(lookup_range) {
|
|
@@ -1558,6 +1556,7 @@ function performLookup(search_key, lookup_array, result_array, missing_value, ma
|
|
|
1558
1556
|
console.log('performLookup called with:', { search_key, lookup_array, result_array, missing_value, match_mode, search_mode, isCol });
|
|
1559
1557
|
|
|
1560
1558
|
let foundIndex = -1;
|
|
1559
|
+
const isSingleResultRow = result_array.length === 1;
|
|
1561
1560
|
|
|
1562
1561
|
// Handle different match modes
|
|
1563
1562
|
switch (match_mode) {
|
|
@@ -1576,34 +1575,27 @@ function performLookup(search_key, lookup_array, result_array, missing_value, ma
|
|
|
1576
1575
|
}
|
|
1577
1576
|
|
|
1578
1577
|
if (foundIndex === -1) {
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
// Multiple columns
|
|
1582
|
-
const errorArray = new Array(result_array[0].length).fill(missing_value);
|
|
1583
|
-
if (isCol) {
|
|
1584
|
-
// Return as column format: [["error"], ["error"], ...]
|
|
1585
|
-
return errorArray.map(val => [val])
|
|
1586
|
-
} else {
|
|
1587
|
-
// Return as row format: ["error", "error", ...]
|
|
1588
|
-
return errorArray
|
|
1589
|
-
}
|
|
1590
|
-
} else {
|
|
1591
|
-
// Single column - return single missing value (isCol doesn't affect single values)
|
|
1592
|
-
return missing_value
|
|
1593
|
-
}
|
|
1578
|
+
// Return missing_value (single value): "yoo"
|
|
1579
|
+
return missing_value
|
|
1594
1580
|
}
|
|
1595
1581
|
|
|
1596
1582
|
// Return the result
|
|
1597
|
-
if (
|
|
1598
|
-
// Single
|
|
1599
|
-
|
|
1583
|
+
if (isSingleResultRow) {
|
|
1584
|
+
// Single result row - return the entire row regardless of where match was found
|
|
1585
|
+
const resultRow = result_array[0];
|
|
1586
|
+
if (isCol) {
|
|
1587
|
+
return resultRow.map(val => [val])
|
|
1588
|
+
} else {
|
|
1589
|
+
return resultRow
|
|
1590
|
+
}
|
|
1600
1591
|
} else {
|
|
1601
|
-
// Multiple
|
|
1592
|
+
// Multiple result rows
|
|
1602
1593
|
if (isCol) {
|
|
1603
|
-
// Return
|
|
1604
|
-
|
|
1594
|
+
// Return the foundIndex column from all rows: ["e", "r"]
|
|
1595
|
+
const columnValues = result_array.map(row => row[foundIndex]);
|
|
1596
|
+
return columnValues
|
|
1605
1597
|
} else {
|
|
1606
|
-
// Return
|
|
1598
|
+
// Return the entire matched row: ["e", 3, "s", "hj"]
|
|
1607
1599
|
return result_array[foundIndex]
|
|
1608
1600
|
}
|
|
1609
1601
|
}
|
package/lib/esm/index.mjs
CHANGED
|
@@ -1439,51 +1439,47 @@ function VLOOKUP(lookup_value, table_array, col_index_num, range_lookup) {
|
|
|
1439
1439
|
return result
|
|
1440
1440
|
}
|
|
1441
1441
|
|
|
1442
|
-
function XLOOKUP(search_key, lookup_range, result_range, missing_value,
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
const ERROR_VALUE = '#VALUE!';
|
|
1447
|
-
const ERROR_NUM = '#NUM!';
|
|
1448
|
-
|
|
1449
|
-
console.log('XLOOKUP parameters:', { search_key, lookup_range, result_range, missing_value, match_mode, search_mode, isCol });
|
|
1442
|
+
function XLOOKUP(search_key, lookup_range, result_range, missing_value, isColV,match_mode, search_mode) {
|
|
1443
|
+
let isCol = isColV === "true" ? true : false;
|
|
1444
|
+
|
|
1445
|
+
console.log('XLOOKUP parameters:', { search_key, lookup_range, result_range, missing_value, match_mode, search_mode, isCol });
|
|
1450
1446
|
|
|
1451
1447
|
// Validate required parameters
|
|
1452
1448
|
if (search_key === undefined || search_key === null) {
|
|
1453
1449
|
console.log('Error: search_key is required');
|
|
1454
|
-
return
|
|
1450
|
+
return new Error('Error: search_key is required')
|
|
1455
1451
|
}
|
|
1456
1452
|
|
|
1457
1453
|
if (!lookup_range || !result_range) {
|
|
1458
1454
|
console.log('Error: lookup_range and result_range are required');
|
|
1459
|
-
return
|
|
1455
|
+
return new Error('Error: lookup_range and result_range are required')
|
|
1460
1456
|
}
|
|
1461
1457
|
|
|
1462
1458
|
// Validate and normalize lookup_range (must be singular row or column)
|
|
1463
1459
|
let lookup_array = normalizeLookupRange(lookup_range);
|
|
1464
1460
|
if (!lookup_array) {
|
|
1465
1461
|
console.log('Error: lookup_range must be a singular row or column');
|
|
1466
|
-
return
|
|
1462
|
+
return new Error('Error: lookup_range must be a singular row or column')
|
|
1467
1463
|
}
|
|
1468
1464
|
|
|
1469
1465
|
// Validate and normalize result_range
|
|
1470
1466
|
let result_array = normalizeResultRange(result_range);
|
|
1471
1467
|
if (!result_array) {
|
|
1472
1468
|
console.log('Error: Invalid result_range');
|
|
1473
|
-
return
|
|
1469
|
+
return new Error('Error: Invalid result_range')
|
|
1474
1470
|
}
|
|
1475
1471
|
|
|
1476
1472
|
// Validate that lookup and result ranges have compatible dimensions
|
|
1477
|
-
// Exception: if result_range is a single row, it can be returned regardless of lookup_range length
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1473
|
+
// Exception: if result_range is a single row, it can be returned regardless of lookup_range length
|
|
1474
|
+
result_array.map((row) => {
|
|
1475
|
+
if (row.length !== lookup_array.length) {
|
|
1476
|
+
console.log('Error: lookup_range and result_range must have the same number of columns');
|
|
1477
|
+
return new Error('Error: lookup_range and result_range must have the same number of columns/rows')
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1484
1480
|
|
|
1485
1481
|
// Set default parameter values
|
|
1486
|
-
missing_value = missing_value !== undefined ? missing_value :
|
|
1482
|
+
missing_value = missing_value !== undefined ? missing_value : new Error("Error: Didn't find value in XLOOKUP evaluation");
|
|
1487
1483
|
match_mode = match_mode !== undefined ? match_mode : 0;
|
|
1488
1484
|
search_mode = search_mode !== undefined ? search_mode : 1;
|
|
1489
1485
|
isCol = isCol !== undefined ? isCol : false;
|
|
@@ -1491,24 +1487,26 @@ function XLOOKUP(search_key, lookup_range, result_range, missing_value, isCol,ma
|
|
|
1491
1487
|
// Validate match_mode
|
|
1492
1488
|
if (![0, 1, -1, 2].includes(match_mode)) {
|
|
1493
1489
|
console.log('Error: match_mode must be 0, 1, -1, or 2');
|
|
1494
|
-
return
|
|
1490
|
+
return new Error('Error: match_mode must be 0, 1, -1, or 2')
|
|
1495
1491
|
}
|
|
1496
1492
|
|
|
1497
1493
|
// Validate search_mode
|
|
1498
1494
|
if (![1, -1, 2, -2].includes(search_mode)) {
|
|
1499
1495
|
console.log('Error: search_mode must be 1, -1, 2, or -2');
|
|
1500
|
-
return
|
|
1496
|
+
return new Error('Error: search_mode must be 1, -1, 2, or -2')
|
|
1501
1497
|
}
|
|
1502
1498
|
|
|
1503
1499
|
// Validate binary search requirements
|
|
1504
1500
|
if (Math.abs(search_mode) === 2 && match_mode === 2) {
|
|
1505
1501
|
console.log('Error: Binary search (search_mode ±2) cannot be used with wildcard matching (match_mode 2)');
|
|
1506
|
-
return
|
|
1502
|
+
return new Error('Error: Binary search (search_mode ±2) cannot be used with wildcard matching (match_mode 2)')
|
|
1507
1503
|
}
|
|
1508
1504
|
|
|
1509
1505
|
console.log('Normalized arrays:', { lookup_array, result_array });
|
|
1510
1506
|
|
|
1511
|
-
|
|
1507
|
+
let res = performLookup(search_key, lookup_array, result_array, missing_value, match_mode, search_mode, isCol);
|
|
1508
|
+
res = isCol ? Array.isArray(res)?res.map((item) => [item.toString()]):res : res;
|
|
1509
|
+
return res
|
|
1512
1510
|
}
|
|
1513
1511
|
|
|
1514
1512
|
function normalizeLookupRange(lookup_range) {
|
|
@@ -1556,6 +1554,7 @@ function performLookup(search_key, lookup_array, result_array, missing_value, ma
|
|
|
1556
1554
|
console.log('performLookup called with:', { search_key, lookup_array, result_array, missing_value, match_mode, search_mode, isCol });
|
|
1557
1555
|
|
|
1558
1556
|
let foundIndex = -1;
|
|
1557
|
+
const isSingleResultRow = result_array.length === 1;
|
|
1559
1558
|
|
|
1560
1559
|
// Handle different match modes
|
|
1561
1560
|
switch (match_mode) {
|
|
@@ -1574,34 +1573,27 @@ function performLookup(search_key, lookup_array, result_array, missing_value, ma
|
|
|
1574
1573
|
}
|
|
1575
1574
|
|
|
1576
1575
|
if (foundIndex === -1) {
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
// Multiple columns
|
|
1580
|
-
const errorArray = new Array(result_array[0].length).fill(missing_value);
|
|
1581
|
-
if (isCol) {
|
|
1582
|
-
// Return as column format: [["error"], ["error"], ...]
|
|
1583
|
-
return errorArray.map(val => [val])
|
|
1584
|
-
} else {
|
|
1585
|
-
// Return as row format: ["error", "error", ...]
|
|
1586
|
-
return errorArray
|
|
1587
|
-
}
|
|
1588
|
-
} else {
|
|
1589
|
-
// Single column - return single missing value (isCol doesn't affect single values)
|
|
1590
|
-
return missing_value
|
|
1591
|
-
}
|
|
1576
|
+
// Return missing_value (single value): "yoo"
|
|
1577
|
+
return missing_value
|
|
1592
1578
|
}
|
|
1593
1579
|
|
|
1594
1580
|
// Return the result
|
|
1595
|
-
if (
|
|
1596
|
-
// Single
|
|
1597
|
-
|
|
1581
|
+
if (isSingleResultRow) {
|
|
1582
|
+
// Single result row - return the entire row regardless of where match was found
|
|
1583
|
+
const resultRow = result_array[0];
|
|
1584
|
+
if (isCol) {
|
|
1585
|
+
return resultRow.map(val => [val])
|
|
1586
|
+
} else {
|
|
1587
|
+
return resultRow
|
|
1588
|
+
}
|
|
1598
1589
|
} else {
|
|
1599
|
-
// Multiple
|
|
1590
|
+
// Multiple result rows
|
|
1600
1591
|
if (isCol) {
|
|
1601
|
-
// Return
|
|
1602
|
-
|
|
1592
|
+
// Return the foundIndex column from all rows: ["e", "r"]
|
|
1593
|
+
const columnValues = result_array.map(row => row[foundIndex]);
|
|
1594
|
+
return columnValues
|
|
1603
1595
|
} else {
|
|
1604
|
-
// Return
|
|
1596
|
+
// Return the entire matched row: ["e", 3, "s", "hj"]
|
|
1605
1597
|
return result_array[foundIndex]
|
|
1606
1598
|
}
|
|
1607
1599
|
}
|
package/package.json
CHANGED
package/types/cjs/index.d.cts
CHANGED
|
@@ -4522,7 +4522,7 @@ export function WORKDAY_INTL(start_date: any, days: any, weekend: any, holidays:
|
|
|
4522
4522
|
* @returns
|
|
4523
4523
|
*/
|
|
4524
4524
|
export function XIRR(values: any, dates: any, guess: any): any;
|
|
4525
|
-
export function XLOOKUP(search_key: any, lookup_range: any, result_range: any, missing_value: any,
|
|
4525
|
+
export function XLOOKUP(search_key: any, lookup_range: any, result_range: any, missing_value: any, isColV: any, match_mode: any, search_mode: any): any;
|
|
4526
4526
|
/**
|
|
4527
4527
|
* Returns the net present value for a schedule of cash flows that is not necessarily periodic.
|
|
4528
4528
|
*
|
package/types/esm/index.d.mts
CHANGED
|
@@ -4522,7 +4522,7 @@ export function WORKDAY_INTL(start_date: any, days: any, weekend: any, holidays:
|
|
|
4522
4522
|
* @returns
|
|
4523
4523
|
*/
|
|
4524
4524
|
export function XIRR(values: any, dates: any, guess: any): any;
|
|
4525
|
-
export function XLOOKUP(search_key: any, lookup_range: any, result_range: any, missing_value: any,
|
|
4525
|
+
export function XLOOKUP(search_key: any, lookup_range: any, result_range: any, missing_value: any, isColV: any, match_mode: any, search_mode: any): any;
|
|
4526
4526
|
/**
|
|
4527
4527
|
* Returns the net present value for a schedule of cash flows that is not necessarily periodic.
|
|
4528
4528
|
*
|