forked from CacheControl/json-rules-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathengine-default-operators.js
50 lines (42 loc) · 1.45 KB
/
engine-default-operators.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _operator = require('./operator');
var _operator2 = _interopRequireDefault(_operator);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Operators = [];
Operators.push(new _operator2.default('equal', function (a, b) {
return a === b;
}));
Operators.push(new _operator2.default('notEqual', function (a, b) {
return a !== b;
}));
Operators.push(new _operator2.default('in', function (a, b) {
return b.indexOf(a) > -1;
}));
Operators.push(new _operator2.default('notIn', function (a, b) {
return b.indexOf(a) === -1;
}));
Operators.push(new _operator2.default('contains', function (a, b) {
return a.indexOf(b) > -1;
}, Array.isArray));
Operators.push(new _operator2.default('doesNotContain', function (a, b) {
return a.indexOf(b) === -1;
}, Array.isArray));
function numberValidator(factValue) {
return Number.parseFloat(factValue).toString() !== 'NaN';
}
Operators.push(new _operator2.default('lessThan', function (a, b) {
return a < b;
}, numberValidator));
Operators.push(new _operator2.default('lessThanInclusive', function (a, b) {
return a <= b;
}, numberValidator));
Operators.push(new _operator2.default('greaterThan', function (a, b) {
return a > b;
}, numberValidator));
Operators.push(new _operator2.default('greaterThanInclusive', function (a, b) {
return a >= b;
}, numberValidator));
exports.default = Operators;