Skip to content
A simple top-down parser for advanced search queries
TypeScript JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Initial commit Feb 12, 2020
.gitignore Initial commit Feb 12, 2020
.travis.yml Run test Feb 12, 2020
CONTRIBUTING.md Add contribution guide Feb 12, 2020
LICENSE
README.md Update README.md Feb 13, 2020
jest.config.js Initial commit Feb 12, 2020
package-lock.json Initial commit Feb 12, 2020
package.json Include repository Feb 13, 2020
tsconfig.json Fix Feb 12, 2020

README.md

qparse

Build Status

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.

Installation

# Using npm
npm install --save qparse

# Using yarn
yarn add qparse

Usage

parse(str, keywords)

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: {} }

Real World Example

Used by Dnote.

LICENSE

Apache 2.0

You can’t perform that action at this time.