forked from launchdarkly/node-server-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperators.js
66 lines (60 loc) · 1.43 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var operators = {
"in": function(a, b) {
return a === b;
},
"endsWith": function(a, b) {
return typeof a === 'string' && a.endsWith(b);
},
"startsWith": function(a, b) {
return typeof a === 'string' && a.startsWith(b);
},
"matches": function(a, b) {
return typeof b === 'string' && new RegExp(b).test(a);
},
"contains": function(a, b) {
return typeof a === 'string' && a.indexOf(b) > -1;
},
"lessThan": function(a, b) {
return typeof a === 'number' && a < b;
},
"lessThanOrEqual": function(a, b) {
return typeof a === 'number' && a <= b;
},
"greaterThan": function(a, b) {
return typeof a === 'number' && a > b;
},
"greaterThanOrEqual": function(a, b) {
return typeof a === 'number' && a >= b;
},
"before": function(a, b) {
if (typeof a === 'string') {
a = Date.parse(a);
}
if (typeof b === 'string') {
b = Date.parse(b);
}
if (typeof a === 'number' && typeof b === 'number') {
return a < b;
}
return false;
},
"after": function(a, b) {
if (typeof a === 'string') {
a = Date.parse(a);
}
if (typeof b === 'string') {
b = Date.parse(b);
}
if (typeof a === 'number' && typeof b === 'number') {
return a > b;
}
return false;
}
}
var operator_none = function(a, b) {
return false;
}
function fn(op) {
return operators[op] || operator_none;
}
module.exports = {operators: operators, fn: fn};