-
Notifications
You must be signed in to change notification settings - Fork 511
Expand file tree
/
Copy pathengine-default-operators.js
More file actions
26 lines (20 loc) · 1.1 KB
/
engine-default-operators.js
File metadata and controls
26 lines (20 loc) · 1.1 KB
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
'use strict'
import Operator from './operator'
const Operators = []
function isCollection (value) {
return !!(value && (Array.isArray(value) || typeof value === 'string'))
}
Operators.push(new Operator('equal', (a, b) => a === b))
Operators.push(new Operator('notEqual', (a, b) => a !== b))
Operators.push(new Operator('in', (a, b) => isCollection(b) && b.indexOf(a) > -1))
Operators.push(new Operator('notIn', (a, b) => !isCollection(b) || b.indexOf(a) === -1))
Operators.push(new Operator('contains', (a, b) => a.indexOf(b) > -1, isCollection))
Operators.push(new Operator('doesNotContain', (a, b) => a.indexOf(b) === -1, isCollection))
function numberValidator (factValue) {
return typeof factValue !== 'object' && !Number.isNaN(Number.parseFloat(factValue))
}
Operators.push(new Operator('lessThan', (a, b) => a < b, numberValidator))
Operators.push(new Operator('lessThanInclusive', (a, b) => a <= b, numberValidator))
Operators.push(new Operator('greaterThan', (a, b) => a > b, numberValidator))
Operators.push(new Operator('greaterThanInclusive', (a, b) => a >= b, numberValidator))
export default Operators