@mapsql/query-parser

mapsql query parser

Usage no npm install needed!

<script type="module">
  import mapsqlQueryParser from 'https://cdn.skypack.dev/@mapsql/query-parser';
</script>

README

mapsql-query-parser

Travis (.com) codecov coverage semantic-release npm

Motivation

Modularizing the mapsql project.

Installation

$ npm install @mapsql/query-parser

Usage

import queryParser from "@mapsql/query-parser";

const parser = queryParser();

// using the default operator object
const query = parser.transform({ foo: 1, bar: { lt: 20, gte: 10, nte: 15 }, baz: { in: [9, 81] }})

// test foo
query.foo(1) // true
query.foo(2) // false

// test bar
query.bar(12) // true
query.bar(15) // false
query.bar(2) // false

// test baz
query.baz([3, 6, 9, 81]) // true
query.baz([2]) // false

// application
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)) // [{ foo: 1, bar: 12, baz: [3, 6, 9, 81 ] }]

See API documentation

License

MIT © wmik