valid-sift
Check if something is a valid sift filter.
Install
$ npm install --save valid-sift
Usage
Importing
;
or
var isValid = ;
Checking a sift filter
If the filter is valid the function returns true
.
const siftFilter = name: $or: $eq: 'Max' $eq: 'Moritz' age: 13 ; const allowedAttributes = 'name' 'age'; ; // => true
If you pass a filter with a not allowed attribute it returns false
.
const siftFilter = id: $or: $eq: 12 $eq: 13 ;; // => false
If you pass a filter with an invalid operator it returns false
.
const siftFilter = id: $or: $eq: 12 $nope: 13 ;; // => false
API
isValid(filter, [attribute, ...]) => boolean
filter
- the filter to check.attribute
- Allowed attributes in the filter.
or pass the attributes as an array.
isValid(filter, attributes) => boolean
attributes
- Allowed attributes in the filter as an array.
License
MIT © Stoeffel