README
Condition
Create conditional to validate data.
Install
$ npm i -S @tadashi/condition
Usage
See example below.
import 'condition' from '@tadashi/condition'
const data = {
age: 65,
gender: 'F',
city: 'São Paulo',
hasCar: true,
colors: ['red', 'blue']
}
const conditions = [
{
join_operator: 'and',
args: [
{
field: 'gender',
operator: 'eq',
value: 'F'
}, {
field: 'age',
operator: 'gt',
value: 21
}, {
join_operator: 'or',
args: [
{
field: 'city',
operator: 'assigned',
value: false
}, {
field: 'colors',
operator: 'intersection',
value: ['blue', 'green']
}
]
}, {
field: 'hasCar',
operator: 'eq',
value: true
}
]
}
]
const isValid = condition(conditions)
isValid(data) // => true
License
MIT © Thiago Lagden