1.0.6 • Published 4 years ago
aqs v1.0.6
AQS is a query parser library that provides advanced operations comparing to typical query parser libraries.
For example, you can use different operators additional to =, or parse values from string to whatever you want and even define complex logic instead of just using and operator for parameters!
Installation
npm install aqsUsage
Basic
const { parse } = require('aqs');
const parsed = parse('id=3&age=22');Use other operators
const { parse } = require('aqs');
const parsed = parse('id=3&age{gt}22'); // Greater thanUse negative operators
You can add n prefix to operator names or not_ to full name of operators to make them negative.
const { parse } = require('aqs');
const parsed = parse('id=3&age{ne}22'); // Not equalUse with config
const { parse } = require('aqs');
const parsed = parse('id=3&age=22', { paramsConfigs: { age: { defaultValue: 20 } } });Use with custom logic
You can define logic of parameters in logic query string, using parentheses with and and or operators.
Benefit of this feature is that you can allow client side that makes more complex queries instead of simple equal queries.
const { parse } = require('aqs');
const parsed = parse('skill=coding&age=30&experience=8&logic=(and,skill,(or,age,experience))'); // skill==coding and (age==30 or experience==8)Other features
There are some other features such as defining custom operators, parse values, ... that you can find them in examples folder.
List of operators
| Operator | Full-name |
|---|---|
| e | equal |
| i | in |
| sw | startsWith |
| ew | endsWith |
| gt | greaterThan |
| lt | lessThan |
| ge | greaterOrEqual |
| le | lessOrEqual |
| b | between |
| c | contains |
| ic | includes |
| l | like |
| il | ilike |
| r | regex |