qparse
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

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

LICENSE

Apache 2.0

Readme

Keywords

Package Sidebar

Install

npm i qparse

Weekly Downloads

1

Version

0.1.1

License

Apache-2.0

Unpacked Size

39.3 kB

Total Files

12

Last publish

Collaborators

  • sungwoncho