@stackedapp/utils 1.19.0 → 1.20.0
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/dist/conditions.js +18 -0
- package/dist/template.d.ts +1 -1
- package/package.json +1 -1
package/dist/conditions.js
CHANGED
|
@@ -20,6 +20,12 @@ const formatList = (items) => items.length === 2 ? items.join(' and ') : `${item
|
|
|
20
20
|
const calculateDynamicConditionPercent = (dynamicObj, cond) => {
|
|
21
21
|
if (!dynamicObj)
|
|
22
22
|
return 0;
|
|
23
|
+
if (cond.operator === 'is_truthy')
|
|
24
|
+
return dynamicObj[cond.key] ? 100 : 0;
|
|
25
|
+
if (cond.operator === 'is_falsy')
|
|
26
|
+
return !dynamicObj[cond.key] ? 100 : 0;
|
|
27
|
+
if (cond.operator === 'is_defined')
|
|
28
|
+
return dynamicObj[cond.key] != null ? 100 : 0;
|
|
23
29
|
const val = dynamicObj[cond.key];
|
|
24
30
|
if (typeof val !== 'number')
|
|
25
31
|
return 0;
|
|
@@ -1489,6 +1495,12 @@ function evaluateDynamicCondition(dynamicObj, cond, claimMultiplier = 1) {
|
|
|
1489
1495
|
if (!dynamicObj)
|
|
1490
1496
|
return false;
|
|
1491
1497
|
const val = dynamicObj[cond.key];
|
|
1498
|
+
if (cond.operator === 'is_truthy')
|
|
1499
|
+
return !!val;
|
|
1500
|
+
if (cond.operator === 'is_falsy')
|
|
1501
|
+
return !val;
|
|
1502
|
+
if (cond.operator === 'is_defined')
|
|
1503
|
+
return val != null;
|
|
1492
1504
|
if (val == undefined)
|
|
1493
1505
|
return false;
|
|
1494
1506
|
const isNumber = typeof val === 'number';
|
|
@@ -1542,6 +1554,12 @@ function evaluateDynamicCondition(dynamicObj, cond, claimMultiplier = 1) {
|
|
|
1542
1554
|
function getMaxClaimsForDynamicCondition(dynamicObj, cond) {
|
|
1543
1555
|
if (!dynamicObj)
|
|
1544
1556
|
return 0;
|
|
1557
|
+
if (cond.operator === 'is_truthy')
|
|
1558
|
+
return dynamicObj[cond.key] ? Infinity : 0;
|
|
1559
|
+
if (cond.operator === 'is_falsy')
|
|
1560
|
+
return !dynamicObj[cond.key] ? Infinity : 0;
|
|
1561
|
+
if (cond.operator === 'is_defined')
|
|
1562
|
+
return dynamicObj[cond.key] != null ? Infinity : 0;
|
|
1545
1563
|
const val = dynamicObj[cond.key];
|
|
1546
1564
|
if (val === undefined)
|
|
1547
1565
|
return 0;
|
package/dist/template.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare function replaceDynamicConditionKey(key: string, trackers: Record
|
|
|
15
15
|
export declare function replaceDynamicConditionKeys(conditions: Array<StackedDynamicCondition>, trackers: Record<string, any> | undefined): {
|
|
16
16
|
key: string;
|
|
17
17
|
compareTo: string | number | boolean;
|
|
18
|
-
operator: "==" | "!=" | ">" | ">=" | "<" | "<=" | "has" | "not_has";
|
|
18
|
+
operator: "==" | "!=" | ">" | ">=" | "<" | "<=" | "has" | "not_has" | "is_truthy" | "is_falsy" | "is_defined";
|
|
19
19
|
intervalHr?: number;
|
|
20
20
|
}[];
|
|
21
21
|
//# sourceMappingURL=template.d.ts.map
|