A top-down parser to turn advanced search query strings into JavaScript objects.
It has no dependency and provides a simple interface with readable implementation.
# Using npm
npm install --save qparse
# Using yarn
yarn add qparse
Parse the given str
while matching the keywords
.
const q = require('qparse');
q.parse('tag:foo tag:bar sort:baz quz qux', ['tag', 'sort']);
// => { text: 'quz qux', filters: { tag: [ 'foo', 'bar' ], sort: 'baz' } }
q.parse('tag:foo tag:bar sort:baz quz qux', ['tag']);
// => { text: 'sort:baz quz qux', filters: { tag: [ 'foo', 'bar' ] } }
q.parse('tag:foo sort:baz quz qux', ['tag']);
// => { text: 'sort:baz quz qux', filters: { tag: 'foo' } }
q.parse('tag:foo sort:baz quz qux', []);
// => { text: 'tag:foo sort:baz quz qux', filters: {} }
Used by Dnote.
Apache 2.0