@mapsql/query-parser
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i @mapsql/query-parser

Weekly Downloads

8

Version

1.1.1

License

MIT

Unpacked Size

9.16 kB

Total Files

8

Last publish

Collaborators

  • wmik