You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.1 KiB

2 years ago
class Filter {
constructor(options) {
this._options = options
}
_eq(value, key, result) {
let isValid = false
if (result[key] === value) {
isValid = true
}
return isValid
}
_neq(value, key, result) {
let isValid = false
if (result[key] !== value) {
isValid = true
}
return isValid
}
_in(value, key, result) {
let isValid = false
if (!result[key]) {
isValid = false
}
if (Array.isArray(value)) {
let found = false
// run through array
value.forEach((v, index) => {
if (result[key].indexOf(v) !== -1) {
found = true
}
})
if (found) {
isValid = true
}
} else {
if (result[key].indexOf(value) !== -1) {
isValid = true
}
}
return isValid
}
2 years ago
/**
*
*
*/
2 years ago
validate(result) {
let isValid = true
for (const [key, value] of Object.entries(this._options)) {
const operators = Object.keys(value)
operators.forEach((operator) => {
if (!this[operator](value[operator], key, result)) {
isValid = false
}
})
}
return isValid
}
}
module.exports = Filter