@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.
- package/lib/browser/formula.js +33 -30
- package/lib/browser/formula.min.js +2 -2
- package/lib/browser/formula.min.js.map +1 -1
- package/lib/cjs/index.cjs +35 -45
- package/lib/esm/index.mjs +35 -45
- package/package.json +1 -1
package/lib/cjs/index.cjs
CHANGED
|
@@ -1442,50 +1442,44 @@ function VLOOKUP(lookup_value, table_array, col_index_num, range_lookup) {
|
|
|
1442
1442
|
}
|
|
1443
1443
|
|
|
1444
1444
|
function XLOOKUP(search_key, lookup_range, result_range, missing_value, isCol,match_mode, search_mode) {
|
|
1445
|
-
|
|
1446
|
-
const ERROR_NA = '#N/A';
|
|
1447
|
-
const ERROR_REF = '#REF!';
|
|
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 });
|
|
1445
|
+
console.log('XLOOKUP parameters:', { search_key, lookup_range, result_range, missing_value, match_mode, search_mode, isCol });
|
|
1452
1446
|
|
|
1453
1447
|
// Validate required parameters
|
|
1454
1448
|
if (search_key === undefined || search_key === null) {
|
|
1455
1449
|
console.log('Error: search_key is required');
|
|
1456
|
-
return
|
|
1450
|
+
return new Error('Error: search_key is required')
|
|
1457
1451
|
}
|
|
1458
1452
|
|
|
1459
1453
|
if (!lookup_range || !result_range) {
|
|
1460
1454
|
console.log('Error: lookup_range and result_range are required');
|
|
1461
|
-
return
|
|
1455
|
+
return new Error('Error: lookup_range and result_range are required')
|
|
1462
1456
|
}
|
|
1463
1457
|
|
|
1464
1458
|
// Validate and normalize lookup_range (must be singular row or column)
|
|
1465
1459
|
let lookup_array = normalizeLookupRange(lookup_range);
|
|
1466
1460
|
if (!lookup_array) {
|
|
1467
1461
|
console.log('Error: lookup_range must be a singular row or column');
|
|
1468
|
-
return
|
|
1462
|
+
return new Error('Error: lookup_range must be a singular row or column')
|
|
1469
1463
|
}
|
|
1470
1464
|
|
|
1471
1465
|
// Validate and normalize result_range
|
|
1472
1466
|
let result_array = normalizeResultRange(result_range);
|
|
1473
1467
|
if (!result_array) {
|
|
1474
1468
|
console.log('Error: Invalid result_range');
|
|
1475
|
-
return
|
|
1469
|
+
return new Error('Error: Invalid result_range')
|
|
1476
1470
|
}
|
|
1477
1471
|
|
|
1478
1472
|
// 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
|
-
|
|
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
|
+
});
|
|
1486
1480
|
|
|
1487
1481
|
// Set default parameter values
|
|
1488
|
-
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");
|
|
1489
1483
|
match_mode = match_mode !== undefined ? match_mode : 0;
|
|
1490
1484
|
search_mode = search_mode !== undefined ? search_mode : 1;
|
|
1491
1485
|
isCol = isCol !== undefined ? isCol : false;
|
|
@@ -1493,24 +1487,26 @@ function XLOOKUP(search_key, lookup_range, result_range, missing_value, isCol,ma
|
|
|
1493
1487
|
// Validate match_mode
|
|
1494
1488
|
if (![0, 1, -1, 2].includes(match_mode)) {
|
|
1495
1489
|
console.log('Error: match_mode must be 0, 1, -1, or 2');
|
|
1496
|
-
return
|
|
1490
|
+
return new Error('Error: match_mode must be 0, 1, -1, or 2')
|
|
1497
1491
|
}
|
|
1498
1492
|
|
|
1499
1493
|
// Validate search_mode
|
|
1500
1494
|
if (![1, -1, 2, -2].includes(search_mode)) {
|
|
1501
1495
|
console.log('Error: search_mode must be 1, -1, 2, or -2');
|
|
1502
|
-
return
|
|
1496
|
+
return new Error('Error: search_mode must be 1, -1, 2, or -2')
|
|
1503
1497
|
}
|
|
1504
1498
|
|
|
1505
1499
|
// Validate binary search requirements
|
|
1506
1500
|
if (Math.abs(search_mode) === 2 && match_mode === 2) {
|
|
1507
1501
|
console.log('Error: Binary search (search_mode ±2) cannot be used with wildcard matching (match_mode 2)');
|
|
1508
|
-
return
|
|
1502
|
+
return new Error('Error: Binary search (search_mode ±2) cannot be used with wildcard matching (match_mode 2)')
|
|
1509
1503
|
}
|
|
1510
1504
|
|
|
1511
1505
|
console.log('Normalized arrays:', { lookup_array, result_array });
|
|
1512
1506
|
|
|
1513
|
-
|
|
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
|
|
1514
1510
|
}
|
|
1515
1511
|
|
|
1516
1512
|
function normalizeLookupRange(lookup_range) {
|
|
@@ -1558,6 +1554,7 @@ function performLookup(search_key, lookup_array, result_array, missing_value, ma
|
|
|
1558
1554
|
console.log('performLookup called with:', { search_key, lookup_array, result_array, missing_value, match_mode, search_mode, isCol });
|
|
1559
1555
|
|
|
1560
1556
|
let foundIndex = -1;
|
|
1557
|
+
const isSingleResultRow = result_array.length === 1;
|
|
1561
1558
|
|
|
1562
1559
|
// Handle different match modes
|
|
1563
1560
|
switch (match_mode) {
|
|
@@ -1576,34 +1573,27 @@ function performLookup(search_key, lookup_array, result_array, missing_value, ma
|
|
|
1576
1573
|
}
|
|
1577
1574
|
|
|
1578
1575
|
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
|
-
}
|
|
1576
|
+
// Return missing_value (single value): "yoo"
|
|
1577
|
+
return missing_value
|
|
1594
1578
|
}
|
|
1595
1579
|
|
|
1596
1580
|
// Return the result
|
|
1597
|
-
if (
|
|
1598
|
-
// Single
|
|
1599
|
-
|
|
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
|
+
}
|
|
1600
1589
|
} else {
|
|
1601
|
-
// Multiple
|
|
1590
|
+
// Multiple result rows
|
|
1602
1591
|
if (isCol) {
|
|
1603
|
-
// Return
|
|
1604
|
-
|
|
1592
|
+
// Return the foundIndex column from all rows: ["e", "r"]
|
|
1593
|
+
const columnValues = result_array.map(row => row[foundIndex]);
|
|
1594
|
+
return columnValues
|
|
1605
1595
|
} else {
|
|
1606
|
-
// Return
|
|
1596
|
+
// Return the entire matched row: ["e", 3, "s", "hj"]
|
|
1607
1597
|
return result_array[foundIndex]
|
|
1608
1598
|
}
|
|
1609
1599
|
}
|
package/lib/esm/index.mjs
CHANGED
|
@@ -1440,50 +1440,44 @@ function VLOOKUP(lookup_value, table_array, col_index_num, range_lookup) {
|
|
|
1440
1440
|
}
|
|
1441
1441
|
|
|
1442
1442
|
function XLOOKUP(search_key, lookup_range, result_range, missing_value, isCol,match_mode, search_mode) {
|
|
1443
|
-
|
|
1444
|
-
const ERROR_NA = '#N/A';
|
|
1445
|
-
const ERROR_REF = '#REF!';
|
|
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 });
|
|
1443
|
+
console.log('XLOOKUP parameters:', { search_key, lookup_range, result_range, missing_value, match_mode, search_mode, isCol });
|
|
1450
1444
|
|
|
1451
1445
|
// Validate required parameters
|
|
1452
1446
|
if (search_key === undefined || search_key === null) {
|
|
1453
1447
|
console.log('Error: search_key is required');
|
|
1454
|
-
return
|
|
1448
|
+
return new Error('Error: search_key is required')
|
|
1455
1449
|
}
|
|
1456
1450
|
|
|
1457
1451
|
if (!lookup_range || !result_range) {
|
|
1458
1452
|
console.log('Error: lookup_range and result_range are required');
|
|
1459
|
-
return
|
|
1453
|
+
return new Error('Error: lookup_range and result_range are required')
|
|
1460
1454
|
}
|
|
1461
1455
|
|
|
1462
1456
|
// Validate and normalize lookup_range (must be singular row or column)
|
|
1463
1457
|
let lookup_array = normalizeLookupRange(lookup_range);
|
|
1464
1458
|
if (!lookup_array) {
|
|
1465
1459
|
console.log('Error: lookup_range must be a singular row or column');
|
|
1466
|
-
return
|
|
1460
|
+
return new Error('Error: lookup_range must be a singular row or column')
|
|
1467
1461
|
}
|
|
1468
1462
|
|
|
1469
1463
|
// Validate and normalize result_range
|
|
1470
1464
|
let result_array = normalizeResultRange(result_range);
|
|
1471
1465
|
if (!result_array) {
|
|
1472
1466
|
console.log('Error: Invalid result_range');
|
|
1473
|
-
return
|
|
1467
|
+
return new Error('Error: Invalid result_range')
|
|
1474
1468
|
}
|
|
1475
1469
|
|
|
1476
1470
|
// 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
|
-
|
|
1471
|
+
// Exception: if result_range is a single row, it can be returned regardless of lookup_range length
|
|
1472
|
+
result_array.map((row) => {
|
|
1473
|
+
if (row.length !== lookup_array.length) {
|
|
1474
|
+
console.log('Error: lookup_range and result_range must have the same number of columns');
|
|
1475
|
+
return new Error('Error: lookup_range and result_range must have the same number of columns/rows')
|
|
1476
|
+
}
|
|
1477
|
+
});
|
|
1484
1478
|
|
|
1485
1479
|
// Set default parameter values
|
|
1486
|
-
missing_value = missing_value !== undefined ? missing_value :
|
|
1480
|
+
missing_value = missing_value !== undefined ? missing_value : new Error("Error: Didn't find value in XLOOKUP evaluation");
|
|
1487
1481
|
match_mode = match_mode !== undefined ? match_mode : 0;
|
|
1488
1482
|
search_mode = search_mode !== undefined ? search_mode : 1;
|
|
1489
1483
|
isCol = isCol !== undefined ? isCol : false;
|
|
@@ -1491,24 +1485,26 @@ function XLOOKUP(search_key, lookup_range, result_range, missing_value, isCol,ma
|
|
|
1491
1485
|
// Validate match_mode
|
|
1492
1486
|
if (![0, 1, -1, 2].includes(match_mode)) {
|
|
1493
1487
|
console.log('Error: match_mode must be 0, 1, -1, or 2');
|
|
1494
|
-
return
|
|
1488
|
+
return new Error('Error: match_mode must be 0, 1, -1, or 2')
|
|
1495
1489
|
}
|
|
1496
1490
|
|
|
1497
1491
|
// Validate search_mode
|
|
1498
1492
|
if (![1, -1, 2, -2].includes(search_mode)) {
|
|
1499
1493
|
console.log('Error: search_mode must be 1, -1, 2, or -2');
|
|
1500
|
-
return
|
|
1494
|
+
return new Error('Error: search_mode must be 1, -1, 2, or -2')
|
|
1501
1495
|
}
|
|
1502
1496
|
|
|
1503
1497
|
// Validate binary search requirements
|
|
1504
1498
|
if (Math.abs(search_mode) === 2 && match_mode === 2) {
|
|
1505
1499
|
console.log('Error: Binary search (search_mode ±2) cannot be used with wildcard matching (match_mode 2)');
|
|
1506
|
-
return
|
|
1500
|
+
return new Error('Error: Binary search (search_mode ±2) cannot be used with wildcard matching (match_mode 2)')
|
|
1507
1501
|
}
|
|
1508
1502
|
|
|
1509
1503
|
console.log('Normalized arrays:', { lookup_array, result_array });
|
|
1510
1504
|
|
|
1511
|
-
|
|
1505
|
+
let res = performLookup(search_key, lookup_array, result_array, missing_value, match_mode, search_mode, isCol);
|
|
1506
|
+
res = isCol ? Array.isArray(res)?res.map((item) => [item.toString()]):res : res;
|
|
1507
|
+
return res
|
|
1512
1508
|
}
|
|
1513
1509
|
|
|
1514
1510
|
function normalizeLookupRange(lookup_range) {
|
|
@@ -1556,6 +1552,7 @@ function performLookup(search_key, lookup_array, result_array, missing_value, ma
|
|
|
1556
1552
|
console.log('performLookup called with:', { search_key, lookup_array, result_array, missing_value, match_mode, search_mode, isCol });
|
|
1557
1553
|
|
|
1558
1554
|
let foundIndex = -1;
|
|
1555
|
+
const isSingleResultRow = result_array.length === 1;
|
|
1559
1556
|
|
|
1560
1557
|
// Handle different match modes
|
|
1561
1558
|
switch (match_mode) {
|
|
@@ -1574,34 +1571,27 @@ function performLookup(search_key, lookup_array, result_array, missing_value, ma
|
|
|
1574
1571
|
}
|
|
1575
1572
|
|
|
1576
1573
|
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
|
-
}
|
|
1574
|
+
// Return missing_value (single value): "yoo"
|
|
1575
|
+
return missing_value
|
|
1592
1576
|
}
|
|
1593
1577
|
|
|
1594
1578
|
// Return the result
|
|
1595
|
-
if (
|
|
1596
|
-
// Single
|
|
1597
|
-
|
|
1579
|
+
if (isSingleResultRow) {
|
|
1580
|
+
// Single result row - return the entire row regardless of where match was found
|
|
1581
|
+
const resultRow = result_array[0];
|
|
1582
|
+
if (isCol) {
|
|
1583
|
+
return resultRow.map(val => [val])
|
|
1584
|
+
} else {
|
|
1585
|
+
return resultRow
|
|
1586
|
+
}
|
|
1598
1587
|
} else {
|
|
1599
|
-
// Multiple
|
|
1588
|
+
// Multiple result rows
|
|
1600
1589
|
if (isCol) {
|
|
1601
|
-
// Return
|
|
1602
|
-
|
|
1590
|
+
// Return the foundIndex column from all rows: ["e", "r"]
|
|
1591
|
+
const columnValues = result_array.map(row => row[foundIndex]);
|
|
1592
|
+
return columnValues
|
|
1603
1593
|
} else {
|
|
1604
|
-
// Return
|
|
1594
|
+
// Return the entire matched row: ["e", 3, "s", "hj"]
|
|
1605
1595
|
return result_array[foundIndex]
|
|
1606
1596
|
}
|
|
1607
1597
|
}
|