npm i @propero/easy-filter
# Or with yarn
yarn add @propero/easy-filter
For further examples check out the example directory.
import { FilterParser, and, gt, eq } from "@propero/easy-filter";
const parser = new FilterParser();
const parsed = parser.parse("and(lt(age,18),like(firstName,A%))");
/*
{
"op": "and",
"filters": [{
"op": "lt",
"field": "age",
"value": "18"
},{
"op": "like",
"field": "firstName",
"value": "A%"
}]
}
*/
const serialized = parser.serialize(and(gt("age", "21"), eq("name", "Peter,()")));
// and(gt(age,21),eq(name,Peter\,\(\)))