mapsql-query-parser

Motivation
Modularizing the mapsql project.
Installation
$ npm install @mapsql/query-parser
Usage
import queryParser from "@mapsql/query-parser";
const parser = queryParser();
const query = parser.transform({ foo: 1, bar: { lt: 20, gte: 10, nte: 15 }, baz: { in: [9, 81] }})
query.foo(1)
query.foo(2)
query.bar(12)
query.bar(15)
query.bar(2)
query.baz([3, 6, 9, 81])
query.baz([2])
const data = [
{ foo: 1, bar: 12, baz: [3, 6, 9, 81 ] },
{ o: 1, bar: 12, baz: [3, 6, 81 ] },
{ foo: 2, bar: 15, baz: [] },
{ foo: 1, bar: 1, baz: [9, 81] },
{ foo: 3, bar: 18, baz: [9, 81] },
];
const valid = data.filter(object =>
Object.keys(query)
.map(key => key in object ? query[key](object[key]): false)
.every(truthy => truthy))
See API documentation
License
MIT © wmik