Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sungwoncho/qparse
A simple top-down parser for advanced search queries
https://github.com/sungwoncho/qparse
advanced-search parser query-parser search typescript
Last synced: 3 months ago
JSON representation
A simple top-down parser for advanced search queries
- Host: GitHub
- URL: https://github.com/sungwoncho/qparse
- Owner: sungwoncho
- License: apache-2.0
- Created: 2020-02-12T00:23:14.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T23:22:58.000Z (almost 2 years ago)
- Last Synced: 2024-10-09T09:36:46.069Z (3 months ago)
- Topics: advanced-search, parser, query-parser, search, typescript
- Language: TypeScript
- Homepage:
- Size: 110 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# qparse
[![Build Status](https://travis-ci.org/sungwoncho/qparse.svg?branch=master)](https://travis-ci.org/sungwoncho/qparse)
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
```bash
# Using npm
npm install --save qparse# Using yarn
yarn add qparse
```## Usage
### parse(str, keywords)
Parse the given `str` while matching the `keywords`.
```js
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](https://github.com/dnote/dnote).
## LICENSE
Apache 2.0