valid-sift
v1.1.0
Published
Check if something is a valid sift filter
Downloads
27
Readme
valid-sift
Check if something is a valid sift filter.
Install
$ npm install --save valid-sift
Usage
Importing
import isValid from 'valid-sift';
or
var isValid = require('valid-sift');
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'];
valid(siftFilter, ...allowedAttributes); // => true
If you pass a filter with a not allowed attribute it returns false
.
const siftFilter = {
id: {
$or: [{$eq: 12}, {$eq: 13}]
}
};
valid(siftFilter, ...allowedAttributes); // => false
If you pass a filter with an invalid operator it returns false
.
const siftFilter = {
id: {
$or: [{$eq: 12}, {$nope: 13}]
}
};
valid(siftFilter); // => 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