@briza/illogical 1.5.1 → 1.5.2
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/changelog.md +4 -0
- package/lib/illogical.esm.js +64 -55
- package/lib/illogical.js +64 -54
- package/package.json +22 -22
- package/readme.md +1 -1
package/changelog.md
CHANGED
package/lib/illogical.esm.js
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
function _defineProperty(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return obj;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
1
|
/**
|
|
17
2
|
* Is number predicate.
|
|
18
3
|
* @param value Tested value.
|
|
@@ -63,6 +48,21 @@ function isEvaluable(value) {
|
|
|
63
48
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
64
49
|
}
|
|
65
50
|
|
|
51
|
+
function _defineProperty(obj, key, value) {
|
|
52
|
+
if (key in obj) {
|
|
53
|
+
Object.defineProperty(obj, key, {
|
|
54
|
+
value: value,
|
|
55
|
+
enumerable: true,
|
|
56
|
+
configurable: true,
|
|
57
|
+
writable: true
|
|
58
|
+
});
|
|
59
|
+
} else {
|
|
60
|
+
obj[key] = value;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return obj;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
66
|
/**
|
|
67
67
|
* Valid types for context members
|
|
68
68
|
*/
|
|
@@ -97,12 +97,12 @@ class Comparison {
|
|
|
97
97
|
* @param {Operand} right Right operand.
|
|
98
98
|
*/
|
|
99
99
|
constructor(operator, operatorSymbol, left, right) {
|
|
100
|
+
_defineProperty(this, "type", EvaluableType.Expression);
|
|
101
|
+
|
|
100
102
|
this.operator = operator;
|
|
101
103
|
this.operatorSymbol = operatorSymbol;
|
|
102
104
|
this.left = left;
|
|
103
105
|
this.right = right;
|
|
104
|
-
|
|
105
|
-
_defineProperty(this, "type", EvaluableType.Expression);
|
|
106
106
|
}
|
|
107
107
|
/**
|
|
108
108
|
* {@link Evaluable.evaluate}
|
|
@@ -132,9 +132,9 @@ class Comparison {
|
|
|
132
132
|
/**
|
|
133
133
|
* {@link Evaluable.simplify}
|
|
134
134
|
*/
|
|
135
|
-
simplify(
|
|
136
|
-
const left = this.left.simplify(...
|
|
137
|
-
const right = this.right.simplify(...
|
|
135
|
+
simplify() {
|
|
136
|
+
const left = this.left.simplify(...arguments);
|
|
137
|
+
const right = this.right.simplify(...arguments);
|
|
138
138
|
|
|
139
139
|
if (!isEvaluable(left) && !isEvaluable(right)) {
|
|
140
140
|
return this.comparison(left, right);
|
|
@@ -620,9 +620,6 @@ class Value extends Operand {
|
|
|
620
620
|
}
|
|
621
621
|
|
|
622
622
|
super();
|
|
623
|
-
|
|
624
|
-
_defineProperty(this, "value", void 0);
|
|
625
|
-
|
|
626
623
|
this.value = value;
|
|
627
624
|
}
|
|
628
625
|
/**
|
|
@@ -819,11 +816,11 @@ class Logical {
|
|
|
819
816
|
* @param {Evaluable[]} operands Collection of operands.
|
|
820
817
|
*/
|
|
821
818
|
constructor(operator, operatorSymbol, operands) {
|
|
819
|
+
_defineProperty(this, "type", EvaluableType.Expression);
|
|
820
|
+
|
|
822
821
|
this.operator = operator;
|
|
823
822
|
this.operatorSymbol = operatorSymbol;
|
|
824
823
|
this.operands = operands;
|
|
825
|
-
|
|
826
|
-
_defineProperty(this, "type", EvaluableType.Expression);
|
|
827
824
|
}
|
|
828
825
|
/**
|
|
829
826
|
* {@link Evaluable.evaluate}
|
|
@@ -891,7 +888,11 @@ class And extends Logical {
|
|
|
891
888
|
*/
|
|
892
889
|
|
|
893
890
|
|
|
894
|
-
simplify(
|
|
891
|
+
simplify() {
|
|
892
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
893
|
+
args[_key] = arguments[_key];
|
|
894
|
+
}
|
|
895
|
+
|
|
895
896
|
const simplified = this.operands.reduce((result, child) => {
|
|
896
897
|
if (result !== false) {
|
|
897
898
|
const childResult = child.simplify(...args);
|
|
@@ -963,8 +964,8 @@ class Not extends Logical {
|
|
|
963
964
|
*/
|
|
964
965
|
|
|
965
966
|
|
|
966
|
-
simplify(
|
|
967
|
-
const simplified = this.operands[0].simplify(...
|
|
967
|
+
simplify() {
|
|
968
|
+
const simplified = this.operands[0].simplify(...arguments);
|
|
968
969
|
|
|
969
970
|
if (isBoolean(simplified)) {
|
|
970
971
|
return !simplified;
|
|
@@ -1017,7 +1018,11 @@ class Nor extends Logical {
|
|
|
1017
1018
|
*/
|
|
1018
1019
|
|
|
1019
1020
|
|
|
1020
|
-
simplify(
|
|
1021
|
+
simplify() {
|
|
1022
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1023
|
+
args[_key] = arguments[_key];
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1021
1026
|
const simplified = this.operands.reduce((result, child) => {
|
|
1022
1027
|
if (result !== false) {
|
|
1023
1028
|
const childResult = child.simplify(...args);
|
|
@@ -1089,7 +1094,11 @@ class Or extends Logical {
|
|
|
1089
1094
|
*/
|
|
1090
1095
|
|
|
1091
1096
|
|
|
1092
|
-
simplify(
|
|
1097
|
+
simplify() {
|
|
1098
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1099
|
+
args[_key] = arguments[_key];
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1093
1102
|
const simplified = this.operands.reduce((result, child) => {
|
|
1094
1103
|
if (result !== true) {
|
|
1095
1104
|
const childResult = child.simplify(...args);
|
|
@@ -1176,8 +1185,14 @@ class Xor extends Logical {
|
|
|
1176
1185
|
*/
|
|
1177
1186
|
|
|
1178
1187
|
|
|
1179
|
-
simplify(
|
|
1180
|
-
|
|
1188
|
+
simplify() {
|
|
1189
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1190
|
+
args[_key] = arguments[_key];
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
const [evaluablesLeft, trueCount] = this.operands.reduce((_ref, child) => {
|
|
1194
|
+
let [notSimplifiedConditions, trueCount] = _ref;
|
|
1195
|
+
|
|
1181
1196
|
if (trueCount > 1) {
|
|
1182
1197
|
return [notSimplifiedConditions, trueCount];
|
|
1183
1198
|
}
|
|
@@ -1230,9 +1245,6 @@ class Collection extends Operand {
|
|
|
1230
1245
|
*/
|
|
1231
1246
|
constructor(items) {
|
|
1232
1247
|
super();
|
|
1233
|
-
|
|
1234
|
-
_defineProperty(this, "items", void 0);
|
|
1235
|
-
|
|
1236
1248
|
this.items = items;
|
|
1237
1249
|
}
|
|
1238
1250
|
/**
|
|
@@ -1250,11 +1262,11 @@ class Collection extends Operand {
|
|
|
1250
1262
|
*/
|
|
1251
1263
|
|
|
1252
1264
|
|
|
1253
|
-
simplify(
|
|
1265
|
+
simplify() {
|
|
1254
1266
|
const values = [];
|
|
1255
1267
|
|
|
1256
1268
|
for (const item of this.items) {
|
|
1257
|
-
const simplifiedItem = item.simplify(...
|
|
1269
|
+
const simplifiedItem = item.simplify(...arguments);
|
|
1258
1270
|
|
|
1259
1271
|
if (isEvaluable(simplifiedItem)) {
|
|
1260
1272
|
return this;
|
|
@@ -1415,11 +1427,6 @@ class Reference extends Operand {
|
|
|
1415
1427
|
}
|
|
1416
1428
|
|
|
1417
1429
|
super();
|
|
1418
|
-
|
|
1419
|
-
_defineProperty(this, "key", void 0);
|
|
1420
|
-
|
|
1421
|
-
_defineProperty(this, "dataType", void 0);
|
|
1422
|
-
|
|
1423
1430
|
this.key = key;
|
|
1424
1431
|
const dataTypeMatch = dataTypeRegex.exec(this.key);
|
|
1425
1432
|
|
|
@@ -1466,9 +1473,10 @@ class Reference extends Operand {
|
|
|
1466
1473
|
*/
|
|
1467
1474
|
|
|
1468
1475
|
|
|
1469
|
-
serialize({
|
|
1470
|
-
|
|
1471
|
-
|
|
1476
|
+
serialize(_ref) {
|
|
1477
|
+
let {
|
|
1478
|
+
referenceSerialization
|
|
1479
|
+
} = _ref;
|
|
1472
1480
|
const key = this.dataType ? `${this.key}.(${this.dataType})` : this.key;
|
|
1473
1481
|
return referenceSerialization(key);
|
|
1474
1482
|
}
|
|
@@ -1559,10 +1567,6 @@ class Parser {
|
|
|
1559
1567
|
* @param {Options?} options Parser options.
|
|
1560
1568
|
*/
|
|
1561
1569
|
constructor(options) {
|
|
1562
|
-
_defineProperty(this, "opts", void 0);
|
|
1563
|
-
|
|
1564
|
-
_defineProperty(this, "expectedOperators", void 0);
|
|
1565
|
-
|
|
1566
1570
|
this.opts = { ...defaultOptions
|
|
1567
1571
|
}; // Apply exclusive options overrides
|
|
1568
1572
|
|
|
@@ -1611,6 +1615,8 @@ class Parser {
|
|
|
1611
1615
|
|
|
1612
1616
|
|
|
1613
1617
|
parseRawExp(raw) {
|
|
1618
|
+
var _this = this;
|
|
1619
|
+
|
|
1614
1620
|
// Value / Reference
|
|
1615
1621
|
if (!Array.isArray(raw)) {
|
|
1616
1622
|
return this.getOperand(raw);
|
|
@@ -1632,9 +1638,11 @@ class Parser {
|
|
|
1632
1638
|
* @param collapsible
|
|
1633
1639
|
*/
|
|
1634
1640
|
|
|
1635
|
-
const logicalExpressionReducer = (operands
|
|
1641
|
+
const logicalExpressionReducer = function (operands) {
|
|
1642
|
+
let collapsible = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1643
|
+
|
|
1636
1644
|
if (operands.length === 0 || operands.filter(operand => operand.type === EvaluableType.Expression).length === 0) {
|
|
1637
|
-
return
|
|
1645
|
+
return _this.getOperand(raw);
|
|
1638
1646
|
}
|
|
1639
1647
|
|
|
1640
1648
|
return collapsible && operands.length === 1 ? operands[0] : undefined;
|
|
@@ -1768,6 +1776,10 @@ class Parser {
|
|
|
1768
1776
|
|
|
1769
1777
|
}
|
|
1770
1778
|
|
|
1779
|
+
/**
|
|
1780
|
+
* Main module.
|
|
1781
|
+
* @module illogical
|
|
1782
|
+
*/
|
|
1771
1783
|
/**
|
|
1772
1784
|
* Condition engine
|
|
1773
1785
|
*/
|
|
@@ -1778,8 +1790,6 @@ class Engine {
|
|
|
1778
1790
|
* @param {Options?} options Parser options.
|
|
1779
1791
|
*/
|
|
1780
1792
|
constructor(options) {
|
|
1781
|
-
_defineProperty(this, "parser", void 0);
|
|
1782
|
-
|
|
1783
1793
|
this.parser = new Parser(options);
|
|
1784
1794
|
}
|
|
1785
1795
|
/**
|
|
@@ -1846,5 +1856,4 @@ class Engine {
|
|
|
1846
1856
|
|
|
1847
1857
|
}
|
|
1848
1858
|
|
|
1849
|
-
export default
|
|
1850
|
-
export { OPERATOR$4 as OPERATOR_AND, OPERATOR$h as OPERATOR_EQ, OPERATOR$g as OPERATOR_GE, OPERATOR$f as OPERATOR_GT, OPERATOR$e as OPERATOR_IN, OPERATOR$d as OPERATOR_LE, OPERATOR$c as OPERATOR_LT, OPERATOR$b as OPERATOR_NE, OPERATOR$2 as OPERATOR_NOR, OPERATOR$3 as OPERATOR_NOT, OPERATOR$a as OPERATOR_NOT_IN, OPERATOR$1 as OPERATOR_OR, OPERATOR$9 as OPERATOR_OVERLAP, OPERATOR$8 as OPERATOR_PREFIX, OPERATOR$7 as OPERATOR_PRESENT, OPERATOR$6 as OPERATOR_SUFFIX, OPERATOR$5 as OPERATOR_UNDEFINED, OPERATOR as OPERATOR_XOR };
|
|
1859
|
+
export { OPERATOR$4 as OPERATOR_AND, OPERATOR$h as OPERATOR_EQ, OPERATOR$g as OPERATOR_GE, OPERATOR$f as OPERATOR_GT, OPERATOR$e as OPERATOR_IN, OPERATOR$d as OPERATOR_LE, OPERATOR$c as OPERATOR_LT, OPERATOR$b as OPERATOR_NE, OPERATOR$2 as OPERATOR_NOR, OPERATOR$3 as OPERATOR_NOT, OPERATOR$a as OPERATOR_NOT_IN, OPERATOR$1 as OPERATOR_OR, OPERATOR$9 as OPERATOR_OVERLAP, OPERATOR$8 as OPERATOR_PREFIX, OPERATOR$7 as OPERATOR_PRESENT, OPERATOR$6 as OPERATOR_SUFFIX, OPERATOR$5 as OPERATOR_UNDEFINED, OPERATOR as OPERATOR_XOR, Engine as default };
|
package/lib/illogical.js
CHANGED
|
@@ -2,21 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
function _defineProperty(obj, key, value) {
|
|
6
|
-
if (key in obj) {
|
|
7
|
-
Object.defineProperty(obj, key, {
|
|
8
|
-
value: value,
|
|
9
|
-
enumerable: true,
|
|
10
|
-
configurable: true,
|
|
11
|
-
writable: true
|
|
12
|
-
});
|
|
13
|
-
} else {
|
|
14
|
-
obj[key] = value;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return obj;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
5
|
/**
|
|
21
6
|
* Is number predicate.
|
|
22
7
|
* @param value Tested value.
|
|
@@ -67,6 +52,21 @@ function isEvaluable(value) {
|
|
|
67
52
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
68
53
|
}
|
|
69
54
|
|
|
55
|
+
function _defineProperty(obj, key, value) {
|
|
56
|
+
if (key in obj) {
|
|
57
|
+
Object.defineProperty(obj, key, {
|
|
58
|
+
value: value,
|
|
59
|
+
enumerable: true,
|
|
60
|
+
configurable: true,
|
|
61
|
+
writable: true
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
obj[key] = value;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return obj;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
70
|
/**
|
|
71
71
|
* Valid types for context members
|
|
72
72
|
*/
|
|
@@ -101,12 +101,12 @@ class Comparison {
|
|
|
101
101
|
* @param {Operand} right Right operand.
|
|
102
102
|
*/
|
|
103
103
|
constructor(operator, operatorSymbol, left, right) {
|
|
104
|
+
_defineProperty(this, "type", EvaluableType.Expression);
|
|
105
|
+
|
|
104
106
|
this.operator = operator;
|
|
105
107
|
this.operatorSymbol = operatorSymbol;
|
|
106
108
|
this.left = left;
|
|
107
109
|
this.right = right;
|
|
108
|
-
|
|
109
|
-
_defineProperty(this, "type", EvaluableType.Expression);
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* {@link Evaluable.evaluate}
|
|
@@ -136,9 +136,9 @@ class Comparison {
|
|
|
136
136
|
/**
|
|
137
137
|
* {@link Evaluable.simplify}
|
|
138
138
|
*/
|
|
139
|
-
simplify(
|
|
140
|
-
const left = this.left.simplify(...
|
|
141
|
-
const right = this.right.simplify(...
|
|
139
|
+
simplify() {
|
|
140
|
+
const left = this.left.simplify(...arguments);
|
|
141
|
+
const right = this.right.simplify(...arguments);
|
|
142
142
|
|
|
143
143
|
if (!isEvaluable(left) && !isEvaluable(right)) {
|
|
144
144
|
return this.comparison(left, right);
|
|
@@ -624,9 +624,6 @@ class Value extends Operand {
|
|
|
624
624
|
}
|
|
625
625
|
|
|
626
626
|
super();
|
|
627
|
-
|
|
628
|
-
_defineProperty(this, "value", void 0);
|
|
629
|
-
|
|
630
627
|
this.value = value;
|
|
631
628
|
}
|
|
632
629
|
/**
|
|
@@ -823,11 +820,11 @@ class Logical {
|
|
|
823
820
|
* @param {Evaluable[]} operands Collection of operands.
|
|
824
821
|
*/
|
|
825
822
|
constructor(operator, operatorSymbol, operands) {
|
|
823
|
+
_defineProperty(this, "type", EvaluableType.Expression);
|
|
824
|
+
|
|
826
825
|
this.operator = operator;
|
|
827
826
|
this.operatorSymbol = operatorSymbol;
|
|
828
827
|
this.operands = operands;
|
|
829
|
-
|
|
830
|
-
_defineProperty(this, "type", EvaluableType.Expression);
|
|
831
828
|
}
|
|
832
829
|
/**
|
|
833
830
|
* {@link Evaluable.evaluate}
|
|
@@ -895,7 +892,11 @@ class And extends Logical {
|
|
|
895
892
|
*/
|
|
896
893
|
|
|
897
894
|
|
|
898
|
-
simplify(
|
|
895
|
+
simplify() {
|
|
896
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
897
|
+
args[_key] = arguments[_key];
|
|
898
|
+
}
|
|
899
|
+
|
|
899
900
|
const simplified = this.operands.reduce((result, child) => {
|
|
900
901
|
if (result !== false) {
|
|
901
902
|
const childResult = child.simplify(...args);
|
|
@@ -967,8 +968,8 @@ class Not extends Logical {
|
|
|
967
968
|
*/
|
|
968
969
|
|
|
969
970
|
|
|
970
|
-
simplify(
|
|
971
|
-
const simplified = this.operands[0].simplify(...
|
|
971
|
+
simplify() {
|
|
972
|
+
const simplified = this.operands[0].simplify(...arguments);
|
|
972
973
|
|
|
973
974
|
if (isBoolean(simplified)) {
|
|
974
975
|
return !simplified;
|
|
@@ -1021,7 +1022,11 @@ class Nor extends Logical {
|
|
|
1021
1022
|
*/
|
|
1022
1023
|
|
|
1023
1024
|
|
|
1024
|
-
simplify(
|
|
1025
|
+
simplify() {
|
|
1026
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1027
|
+
args[_key] = arguments[_key];
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1025
1030
|
const simplified = this.operands.reduce((result, child) => {
|
|
1026
1031
|
if (result !== false) {
|
|
1027
1032
|
const childResult = child.simplify(...args);
|
|
@@ -1093,7 +1098,11 @@ class Or extends Logical {
|
|
|
1093
1098
|
*/
|
|
1094
1099
|
|
|
1095
1100
|
|
|
1096
|
-
simplify(
|
|
1101
|
+
simplify() {
|
|
1102
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1103
|
+
args[_key] = arguments[_key];
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1097
1106
|
const simplified = this.operands.reduce((result, child) => {
|
|
1098
1107
|
if (result !== true) {
|
|
1099
1108
|
const childResult = child.simplify(...args);
|
|
@@ -1180,8 +1189,14 @@ class Xor extends Logical {
|
|
|
1180
1189
|
*/
|
|
1181
1190
|
|
|
1182
1191
|
|
|
1183
|
-
simplify(
|
|
1184
|
-
|
|
1192
|
+
simplify() {
|
|
1193
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1194
|
+
args[_key] = arguments[_key];
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
const [evaluablesLeft, trueCount] = this.operands.reduce((_ref, child) => {
|
|
1198
|
+
let [notSimplifiedConditions, trueCount] = _ref;
|
|
1199
|
+
|
|
1185
1200
|
if (trueCount > 1) {
|
|
1186
1201
|
return [notSimplifiedConditions, trueCount];
|
|
1187
1202
|
}
|
|
@@ -1234,9 +1249,6 @@ class Collection extends Operand {
|
|
|
1234
1249
|
*/
|
|
1235
1250
|
constructor(items) {
|
|
1236
1251
|
super();
|
|
1237
|
-
|
|
1238
|
-
_defineProperty(this, "items", void 0);
|
|
1239
|
-
|
|
1240
1252
|
this.items = items;
|
|
1241
1253
|
}
|
|
1242
1254
|
/**
|
|
@@ -1254,11 +1266,11 @@ class Collection extends Operand {
|
|
|
1254
1266
|
*/
|
|
1255
1267
|
|
|
1256
1268
|
|
|
1257
|
-
simplify(
|
|
1269
|
+
simplify() {
|
|
1258
1270
|
const values = [];
|
|
1259
1271
|
|
|
1260
1272
|
for (const item of this.items) {
|
|
1261
|
-
const simplifiedItem = item.simplify(...
|
|
1273
|
+
const simplifiedItem = item.simplify(...arguments);
|
|
1262
1274
|
|
|
1263
1275
|
if (isEvaluable(simplifiedItem)) {
|
|
1264
1276
|
return this;
|
|
@@ -1419,11 +1431,6 @@ class Reference extends Operand {
|
|
|
1419
1431
|
}
|
|
1420
1432
|
|
|
1421
1433
|
super();
|
|
1422
|
-
|
|
1423
|
-
_defineProperty(this, "key", void 0);
|
|
1424
|
-
|
|
1425
|
-
_defineProperty(this, "dataType", void 0);
|
|
1426
|
-
|
|
1427
1434
|
this.key = key;
|
|
1428
1435
|
const dataTypeMatch = dataTypeRegex.exec(this.key);
|
|
1429
1436
|
|
|
@@ -1470,9 +1477,10 @@ class Reference extends Operand {
|
|
|
1470
1477
|
*/
|
|
1471
1478
|
|
|
1472
1479
|
|
|
1473
|
-
serialize({
|
|
1474
|
-
|
|
1475
|
-
|
|
1480
|
+
serialize(_ref) {
|
|
1481
|
+
let {
|
|
1482
|
+
referenceSerialization
|
|
1483
|
+
} = _ref;
|
|
1476
1484
|
const key = this.dataType ? `${this.key}.(${this.dataType})` : this.key;
|
|
1477
1485
|
return referenceSerialization(key);
|
|
1478
1486
|
}
|
|
@@ -1563,10 +1571,6 @@ class Parser {
|
|
|
1563
1571
|
* @param {Options?} options Parser options.
|
|
1564
1572
|
*/
|
|
1565
1573
|
constructor(options) {
|
|
1566
|
-
_defineProperty(this, "opts", void 0);
|
|
1567
|
-
|
|
1568
|
-
_defineProperty(this, "expectedOperators", void 0);
|
|
1569
|
-
|
|
1570
1574
|
this.opts = { ...defaultOptions
|
|
1571
1575
|
}; // Apply exclusive options overrides
|
|
1572
1576
|
|
|
@@ -1615,6 +1619,8 @@ class Parser {
|
|
|
1615
1619
|
|
|
1616
1620
|
|
|
1617
1621
|
parseRawExp(raw) {
|
|
1622
|
+
var _this = this;
|
|
1623
|
+
|
|
1618
1624
|
// Value / Reference
|
|
1619
1625
|
if (!Array.isArray(raw)) {
|
|
1620
1626
|
return this.getOperand(raw);
|
|
@@ -1636,9 +1642,11 @@ class Parser {
|
|
|
1636
1642
|
* @param collapsible
|
|
1637
1643
|
*/
|
|
1638
1644
|
|
|
1639
|
-
const logicalExpressionReducer = (operands
|
|
1645
|
+
const logicalExpressionReducer = function (operands) {
|
|
1646
|
+
let collapsible = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
1647
|
+
|
|
1640
1648
|
if (operands.length === 0 || operands.filter(operand => operand.type === EvaluableType.Expression).length === 0) {
|
|
1641
|
-
return
|
|
1649
|
+
return _this.getOperand(raw);
|
|
1642
1650
|
}
|
|
1643
1651
|
|
|
1644
1652
|
return collapsible && operands.length === 1 ? operands[0] : undefined;
|
|
@@ -1772,6 +1780,10 @@ class Parser {
|
|
|
1772
1780
|
|
|
1773
1781
|
}
|
|
1774
1782
|
|
|
1783
|
+
/**
|
|
1784
|
+
* Main module.
|
|
1785
|
+
* @module illogical
|
|
1786
|
+
*/
|
|
1775
1787
|
/**
|
|
1776
1788
|
* Condition engine
|
|
1777
1789
|
*/
|
|
@@ -1782,8 +1794,6 @@ class Engine {
|
|
|
1782
1794
|
* @param {Options?} options Parser options.
|
|
1783
1795
|
*/
|
|
1784
1796
|
constructor(options) {
|
|
1785
|
-
_defineProperty(this, "parser", void 0);
|
|
1786
|
-
|
|
1787
1797
|
this.parser = new Parser(options);
|
|
1788
1798
|
}
|
|
1789
1799
|
/**
|
|
@@ -1868,4 +1878,4 @@ exports.OPERATOR_PRESENT = OPERATOR$7;
|
|
|
1868
1878
|
exports.OPERATOR_SUFFIX = OPERATOR$6;
|
|
1869
1879
|
exports.OPERATOR_UNDEFINED = OPERATOR$5;
|
|
1870
1880
|
exports.OPERATOR_XOR = OPERATOR;
|
|
1871
|
-
exports
|
|
1881
|
+
exports["default"] = Engine;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@briza/illogical",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "A micro conditional javascript engine used to parse the raw logical and comparison expressions, evaluate the expression in the given data context, and provide access to a text form of the given expressions.",
|
|
5
5
|
"main": "lib/illogical.js",
|
|
6
6
|
"module": "lib/illogical.esm.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"lint": "eslint --max-warnings 0 \"src/**/*.{ts,js}\"",
|
|
26
26
|
"lint:fix": "eslint --max-warnings 0 \"src/**/*.{ts,js}\" --fix",
|
|
27
27
|
"prepublishOnly": "npm run test && npm run build",
|
|
28
|
-
"check-licenses": "license-checker --summary --excludePrivatePackages --onlyAllow \"MIT;MIT OR X11;Apache-2.0;ISC;BSD-3-Clause;BSD-2-Clause;CC-BY-4.0;Public Domain;BSD;CC-BY-3.0;CC0-1.0;Unlicense\""
|
|
28
|
+
"check-licenses": "license-checker --summary --excludePrivatePackages --onlyAllow \"MIT;MIT OR X11;Apache-2.0;ISC;BSD-3-Clause;BSD-2-Clause;CC-BY-4.0;Public Domain;BSD;CC-BY-3.0;CC0-1.0;Python-2.0;Unlicense\""
|
|
29
29
|
},
|
|
30
30
|
"repository": {
|
|
31
31
|
"type": "git",
|
|
@@ -42,31 +42,31 @@
|
|
|
42
42
|
"rules"
|
|
43
43
|
],
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@babel/core": "^7.
|
|
46
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
47
|
-
"@babel/preset-env": "^7.
|
|
48
|
-
"@babel/preset-typescript": "^7.
|
|
45
|
+
"@babel/core": "^7.16.12",
|
|
46
|
+
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
47
|
+
"@babel/preset-env": "^7.16.11",
|
|
48
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
49
49
|
"@rollup/plugin-babel": "^5.2.3",
|
|
50
|
-
"@rollup/plugin-commonjs": "^
|
|
51
|
-
"@rollup/plugin-node-resolve": "^13.
|
|
52
|
-
"@types/jest": "^27.0
|
|
53
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
54
|
-
"@typescript-eslint/parser": "^
|
|
55
|
-
"eslint": "^
|
|
50
|
+
"@rollup/plugin-commonjs": "^21.0.1",
|
|
51
|
+
"@rollup/plugin-node-resolve": "^13.1.3",
|
|
52
|
+
"@types/jest": "^27.4.0",
|
|
53
|
+
"@typescript-eslint/eslint-plugin": "^5.10.2",
|
|
54
|
+
"@typescript-eslint/parser": "^5.10.2",
|
|
55
|
+
"eslint": "^8.8.0",
|
|
56
56
|
"eslint-config-prettier": "^8.3.0",
|
|
57
|
-
"eslint-import-resolver-typescript": "^2.
|
|
58
|
-
"eslint-plugin-import": "^2.
|
|
57
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
58
|
+
"eslint-plugin-import": "^2.25.4",
|
|
59
59
|
"eslint-plugin-node": "^11.1.0",
|
|
60
|
-
"eslint-plugin-prettier": "^3.4.
|
|
61
|
-
"eslint-plugin-promise": "^
|
|
60
|
+
"eslint-plugin-prettier": "^3.4.1",
|
|
61
|
+
"eslint-plugin-promise": "^6.0.0",
|
|
62
62
|
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
63
|
-
"jest": "^27.
|
|
63
|
+
"jest": "^27.4.7",
|
|
64
64
|
"license-checker": "^25.0.1",
|
|
65
|
-
"prettier": "^2.
|
|
66
|
-
"rollup": "^2.
|
|
65
|
+
"prettier": "^2.5.1",
|
|
66
|
+
"rollup": "^2.66.1",
|
|
67
67
|
"rollup-plugin-eslint": "^7.0.0",
|
|
68
|
-
"ts-jest": "^27.
|
|
69
|
-
"typedoc": "^0.
|
|
70
|
-
"typescript": "^4.
|
|
68
|
+
"ts-jest": "^27.1.3",
|
|
69
|
+
"typedoc": "^0.22.11",
|
|
70
|
+
"typescript": "^4.5.5"
|
|
71
71
|
}
|
|
72
72
|
}
|
package/readme.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A micro conditional javascript engine used to parse the raw logical and comparison expressions, evaluate the expression in the given data context, and provide access to a text form of the given expressions.
|
|
4
4
|
|
|
5
|
-
> Revision:
|
|
5
|
+
> Revision: February 1, 2022.
|
|
6
6
|
|
|
7
7
|
## About
|
|
8
8
|
|