|
3 | 3 | import Operator from './operator' |
4 | 4 |
|
5 | 5 | const Operators = [] |
| 6 | +function isCollection (value) { |
| 7 | + return !!(value && (Array.isArray(value) || typeof value === 'string')) |
| 8 | +} |
| 9 | + |
6 | 10 | Operators.push(new Operator('equal', (a, b) => a === b)) |
7 | 11 | Operators.push(new Operator('notEqual', (a, b) => a !== b)) |
8 | | -Operators.push(new Operator('in', (a, b) => b.indexOf(a) > -1)) |
9 | | -Operators.push(new Operator('notIn', (a, b) => b.indexOf(a) === -1)) |
| 12 | +Operators.push(new Operator('in', (a, b) => isCollection(b) && b.indexOf(a) > -1)) |
| 13 | +Operators.push(new Operator('notIn', (a, b) => !isCollection(b) || b.indexOf(a) === -1)) |
10 | 14 |
|
11 | | -Operators.push(new Operator('contains', (a, b) => a.indexOf(b) > -1, Array.isArray)) |
12 | | -Operators.push(new Operator('doesNotContain', (a, b) => a.indexOf(b) === -1, Array.isArray)) |
| 15 | +Operators.push(new Operator('contains', (a, b) => a.indexOf(b) > -1, isCollection)) |
| 16 | +Operators.push(new Operator('doesNotContain', (a, b) => a.indexOf(b) === -1, isCollection)) |
13 | 17 |
|
14 | 18 | function numberValidator (factValue) { |
15 | | - return Number.parseFloat(factValue).toString() !== 'NaN' |
| 19 | + return typeof factValue !== 'object' && !Number.isNaN(Number.parseFloat(factValue)) |
16 | 20 | } |
17 | 21 | Operators.push(new Operator('lessThan', (a, b) => a < b, numberValidator)) |
18 | 22 | Operators.push(new Operator('lessThanInclusive', (a, b) => a <= b, numberValidator)) |
|
0 commit comments