query-parser.jsx
Synopsis
Google-ish query string parser for JSX/JS/CommonJS/AMD
Motivation
This is a part of Oktavia. This module provides Google-ish query. It supports the following syntax:
AND
:hello world
OR
:hello OR world
NOT
:-hello
RAW
:"hello world"
Code Example
This module provides two classes. These classes
QueryStringParser
: Good for parse query string on HTML forms.QueryListParser
: Good for processing command line tools.
Use from JSX (Query
// QueryStringParser for console;; static : void { domid'search_button'; }
// QueryListParser for console;; static : void { var parser = ; var queries = parser; for var i = 0; i < querieslength; i++ var query = queriesi; console; }
Use from node.js
var QueryStringParser = QueryStringParser;var QueryListParser = QueryListParser;
Use from require.js
// use query-parser.amd.js;
Use via standard JSX function
Use via global variables
Installation
$ npm install query-parser.jsx
If you want to use this library from other JSX project, install like the following:
$ npm install query-parser.jsx --save-dev
or add like these lines to your parent project's package.json
:
devDependencies: "query-parser.jsx": "~0.3.0" peerDepenencies: "query-parser.jsx": "~0.3.0"
And add node_modules/query-parser.jsx/src
as a search path.
You should add to peerDepenencies
if your product is library.
API Reference
This module provides the following two classes:
class QueryListParser()
It is good for prcessing command line parameters. query()
method receives array of string.
class QueryStringParser()
It is good for prcessing search query in text input. query()
method receives string.
QueryParser#parse(query) : void
Parse query.
QueryParser#queries : Query[]
Parse result.
class Query
It has query result. It has the following members:
word : string
or : boolean
not : boolean
raw : boolean
Development
JSX
Don't be afraid JSX! If you have an experience of JavaScript, you can learn JSX quickly.
- Static type system and unified class syntax.
- All variables and methods belong to class.
- JSX includes optimizer. You don't have to write tricky unreadalbe code for speed.
- You can use almost all JavaScript API as you know. Some functions become static class functions. See reference.
Setup
To create development environment, call following command:
$ npm install
Repository
- Repository: git://github.com/shibukawa/query-parser.jsx.git
- Issues: https://github.com/shibukawa/query-parser.jsx/issues
Run Test
$ grunt test
Build
$ grunt build
Generate API reference
$ grunt doc
Author
- shibukawa / yoshiki@shibu.jp
License
MIT
Complete license is written in LICENSE.md
.