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 } /** * * */ 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