@degenerate/rules 0.0.5 → 0.0.8
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/LICENSE.md +15 -0
- package/README.md +1 -0
- package/dist/evaluation/conditions/starts-end-with-conditions.d.ts +1 -1
- package/dist/evaluation/conditions/starts-end-with-conditions.d.ts.map +1 -1
- package/dist/evaluation/conditions/starts-end-with-conditions.js +64 -8
- package/dist/evaluation/conditions/typeof-rule-conditions.js +3 -3
- package/package.json +4 -3
package/LICENSE.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [2024] [Degenerateiinc.ca]
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -11,6 +11,6 @@ import { ConditionTypeStartsEndsWith } from '@degenerate/generic';
|
|
|
11
11
|
*
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
|
-
declare const isValidStartEndWithValue: (dataValue: string | number, conditionValue: string | number, conditionType: ConditionTypeStartsEndsWith) => boolean;
|
|
14
|
+
declare const isValidStartEndWithValue: (dataValue: string | number | (string | number)[], conditionValue: string | number | (string | number)[], conditionType: ConditionTypeStartsEndsWith) => boolean;
|
|
15
15
|
export { isValidStartEndWithValue };
|
|
16
16
|
//# sourceMappingURL=starts-end-with-conditions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"starts-end-with-conditions.d.ts","sourceRoot":"","sources":["../../../src/evaluation/conditions/starts-end-with-conditions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"starts-end-with-conditions.d.ts","sourceRoot":"","sources":["../../../src/evaluation/conditions/starts-end-with-conditions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAEH,2BAA2B,EAI9B,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;GAQG;AACH,QAAA,MAAM,wBAAwB,cAAe,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,kBAAkB,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,iBACtH,2BAA2B,KAAG,OAchD,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
|
|
@@ -16,17 +16,72 @@ const generic_1 = require("@degenerate/generic");
|
|
|
16
16
|
*/
|
|
17
17
|
const isValidStartEndWithValue = (dataValue, conditionValue, conditionType) => {
|
|
18
18
|
// Make sure the data type is correct
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
if (!(typeof dataValue === 'string' || typeof dataValue === 'number' || (0, generic_1.validateArray)(dataValue, 1))) {
|
|
20
|
+
throw new generic_1.SafeRuleEvaluationConditionDataValueError(dataValue, conditionValue, conditionType);
|
|
21
|
+
}
|
|
22
|
+
if (!(typeof conditionValue === 'string' || typeof conditionValue === 'number' || (0, generic_1.validateArray)(conditionValue, 1))) {
|
|
23
|
+
throw new generic_1.SafeRuleEvaluationConditionValueError(dataValue, conditionValue, conditionType);
|
|
24
|
+
}
|
|
25
|
+
if ((typeof dataValue === 'string' || typeof dataValue === 'number') && (typeof conditionValue === 'string' || typeof conditionValue === 'number')) {
|
|
26
|
+
return isValidStartEndWithStringNumberValue(dataValue, conditionValue, conditionType);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
return isValidStartEndWithArrayValue(dataValue, conditionValue, conditionType);
|
|
27
30
|
}
|
|
28
31
|
};
|
|
29
32
|
exports.isValidStartEndWithValue = isValidStartEndWithValue;
|
|
33
|
+
//#region internal functions
|
|
34
|
+
const isValidStartEndWithArrayValue = (dataValue, conditionValue, conditionType) => {
|
|
35
|
+
if ((0, generic_1.validateArray)(dataValue, 1) && (0, generic_1.validateArray)(conditionValue, 1)) {
|
|
36
|
+
// check the datatype is valid
|
|
37
|
+
let dataValueSameType = (0, generic_1.checkIfAllItemsInAnArrayAreSameType)(dataValue, 'string');
|
|
38
|
+
if (!dataValueSameType)
|
|
39
|
+
dataValueSameType = (0, generic_1.checkIfAllItemsInAnArrayAreSameType)(dataValue, 'number');
|
|
40
|
+
if (!dataValueSameType)
|
|
41
|
+
throw new generic_1.SafeRuleEvaluationConditionDataValueError(dataValue, conditionValue, conditionType);
|
|
42
|
+
let conditionValueSameType = (0, generic_1.checkIfAllItemsInAnArrayAreSameType)(conditionValue, 'string');
|
|
43
|
+
if (!conditionValueSameType)
|
|
44
|
+
conditionValueSameType = (0, generic_1.checkIfAllItemsInAnArrayAreSameType)(conditionValue, 'number');
|
|
45
|
+
if (!conditionValueSameType)
|
|
46
|
+
throw new generic_1.SafeRuleEvaluationConditionValueError(dataValue, conditionValue, conditionType);
|
|
47
|
+
const valueToCheck = (conditionType === generic_1.ConditionTypeStartsEndsWith.STARTS_WITH) ?
|
|
48
|
+
dataValue[0] : dataValue[dataValue.length - 1];
|
|
49
|
+
let isValid = false;
|
|
50
|
+
for (const conditionValueElement of conditionValue) {
|
|
51
|
+
if (valueToCheck.toString() === conditionValueElement.toString()) {
|
|
52
|
+
isValid = true;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
;
|
|
56
|
+
}
|
|
57
|
+
return isValid;
|
|
58
|
+
}
|
|
59
|
+
else if ((0, generic_1.validateArray)(dataValue, 1) && (typeof conditionValue === 'string' || typeof conditionValue === 'number')) {
|
|
60
|
+
// check the datatype is valid
|
|
61
|
+
let dataValueSameType = (0, generic_1.checkIfAllItemsInAnArrayAreSameType)(dataValue, 'string');
|
|
62
|
+
if (!dataValueSameType)
|
|
63
|
+
dataValueSameType = (0, generic_1.checkIfAllItemsInAnArrayAreSameType)(dataValue, 'number');
|
|
64
|
+
if (!dataValueSameType)
|
|
65
|
+
throw new generic_1.SafeRuleEvaluationConditionDataValueError(dataValue, conditionValue, conditionType);
|
|
66
|
+
const valueToCheck = (conditionType === generic_1.ConditionTypeStartsEndsWith.STARTS_WITH) ?
|
|
67
|
+
dataValue[0] : dataValue[dataValue.length - 1];
|
|
68
|
+
return valueToCheck.toString() === conditionValue.toString();
|
|
69
|
+
}
|
|
70
|
+
else if ((0, generic_1.validateArray)(conditionValue, 1) && (typeof dataValue === 'string' || typeof dataValue === 'number')) {
|
|
71
|
+
// make sure the condition datatype is valid
|
|
72
|
+
let conditionValueSameType = (0, generic_1.checkIfAllItemsInAnArrayAreSameType)(conditionValue, 'string');
|
|
73
|
+
if (!conditionValueSameType)
|
|
74
|
+
conditionValueSameType = (0, generic_1.checkIfAllItemsInAnArrayAreSameType)(conditionValue, 'number');
|
|
75
|
+
if (!conditionValueSameType)
|
|
76
|
+
throw new generic_1.SafeRuleEvaluationConditionValueError(dataValue, conditionValue, conditionType);
|
|
77
|
+
for (const conditionValueElement of conditionValue) {
|
|
78
|
+
if (isValidStartEndWithStringNumberValue(dataValue, conditionValueElement, conditionType)) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
};
|
|
30
85
|
/**
|
|
31
86
|
* This takes a value and checks if the value starts or ends with value for a string or number
|
|
32
87
|
* @param dataValue the value to check
|
|
@@ -42,3 +97,4 @@ const isValidStartEndWithStringNumberValue = (dataValue, conditionValue, conditi
|
|
|
42
97
|
return dataValue.toString().endsWith(conditionValue.toString());
|
|
43
98
|
}
|
|
44
99
|
};
|
|
100
|
+
//#endregion internal functions
|
|
@@ -30,14 +30,14 @@ const checkType = (dataValue, typeofValue) => {
|
|
|
30
30
|
switch (typeofValue) {
|
|
31
31
|
case generic_1.ConditionTypeOf.STRING:
|
|
32
32
|
return typeof dataValue === 'string';
|
|
33
|
-
case generic_1.ConditionTypeOf.NUMBER:
|
|
34
|
-
return typeof dataValue === 'number';
|
|
35
33
|
case generic_1.ConditionTypeOf.INTEGER:
|
|
36
34
|
return Number.isInteger(dataValue);
|
|
35
|
+
case generic_1.ConditionTypeOf.NUMBER:
|
|
36
|
+
return typeof dataValue === 'number';
|
|
37
37
|
case generic_1.ConditionTypeOf.BOOLEAN:
|
|
38
38
|
return typeof dataValue === 'boolean';
|
|
39
39
|
case generic_1.ConditionTypeOf.OBJECT:
|
|
40
|
-
return typeof dataValue === 'object';
|
|
40
|
+
return typeof dataValue === 'object' && dataValue !== null;
|
|
41
41
|
case generic_1.ConditionTypeOf.ARRAY:
|
|
42
42
|
return Array.isArray(dataValue);
|
|
43
43
|
case generic_1.ConditionTypeOf.NULL:
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@degenerate/rules",
|
|
3
3
|
"description": "This contains the rules information needed for the ShareData Adaptive Framework Ecosystem (SAFE) network.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.8",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"devDependencies": {
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"author": "Degenerate Inc.",
|
|
37
37
|
"license": "ISC",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@degenerate/generic": "^0.0.
|
|
40
|
-
}
|
|
39
|
+
"@degenerate/generic": "^0.0.14"
|
|
40
|
+
},
|
|
41
|
+
"gitHead": "5059d45109891b0ef2bca1fe368767ef7171edef"
|
|
41
42
|
}
|