0.6.1 • Published 8 months ago

@ambassify/aql-parser v0.6.1

Weekly downloads
15
License
MIT
Repository
github
Last release
8 months ago

aql-parser

Parsing utility for AQL components.

Usage

npm install --save @ambassify/aql-parser
const aqlParser = require('@ambassify/aql-parser');

const fields = 'foo,bar,(baz,two)'
const condition = JSON.stringify({ key: 'foo', operator: 'eq', value: 1 });
const order = '-priority,id';
const url = [
    'https://foo.bar/?fiels='
    encodeURIComponent(fields),
    '&condition=',
    encodeURIComponent(condition),
    '&order=',
    encodeURIComponent(order),
].join('');

console.log(aqlParser.fields(fields));
/**
 * {
 *   foo: true,
 *   bar: { baz: true, two: true }
 * }
 */

console.log(aqlParser.condition(condition));
/**
 * { key: 'foo', operator: 'eq', value: 1 }
 *
 * Supports:
 *   - url-encoded JSON string
 *   - JSON string
 *   - url-encoded nested query parameters
 * (see tests for details)
 */

console.log(aqlParser.order(order));
/**
 * [
 *   { key: 'priority', direction: 'descending' },
 *   { key: 'id', direction: 'ascending' }
 * ]
 */

console.log(aqlParser.url(url));
/**
 * {
 *   fields: ...,
 *   condition: ...,
 *   order: ...,
 * }
0.6.1

8 months ago

0.5.0

3 years ago

0.4.0

4 years ago

0.3.0

4 years ago

0.2.0

5 years ago

0.1.1

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago