UNPKG

@gameroom/kit

Version:

Node kit for the Gameroom API

38 lines (33 loc) 899 B
const Expression = require('./Expression') module.exports = class Filter { constructor(data) { if (!data) { this.expression = new Expression() return } if (data.includes) this.includes = data.includes if (data.joins) this.joins = data.joins data = this.parse(data) if (data.and) { this.and = data.and } else if (data.or) { this.or = data.or } else { this.expression = data } Object.defineProperty(this, 'parse', { enumerable: false }) } parse(data) { let result = {} if (data.and) { result.and = data.and.reduce((a, i) => [...a, this.parse(i)], []) } else if (data.or) { result.or = data.or.reduce((a, i) => [...a, this.parse(i)], []) } else if (data.expression) { result = new Expression(data.expression) } else { result = new Expression(data) } return result } }