Skip to content

trycatchjames/quri-js

Repository files navigation

quri-js

NPM version Build Status Coveralls Status Dependency Status Downloads

JS wrapper for the QURI string specification

Install

npm install quri

QURI Spec

More information about the QURI specification and parser is available here.

Usage

Basic example

import Quri from 'quri';

const quri = new Quri();

quri.toString(); // "field_1".eq("my value")

Nested example

import Quri from 'quri';

const quri = new Quri();

quri.appendExpression('field_1', '==', 'outer');

const nestedQuri = new Quri('or');

nestedQuri.appendExpression('field_2', 'like', 'nested%');
nestedQuri.appendExpression('field_3', 'in', [1, 2, 3, 4]);

quri.appendCriteria(nestedQuri);

quri.toString();
// "field_1".eq("outer"),("field_2".eq("nested%")|"field_3".in(1,2,3,4))

Serialization

import Quri from 'quri';

let quri = new Quri();

quri.appendExpression('field_1', '==', 'my value');

quri.serialize();
// { criteria: [ [ 'field_1', '==', 'my value' ] ] }
quri.serialize({ verbose: true });
// { conjunction: 'and', criteria: [ { field: 'field_1', operator: '==', value: 'my value' } ] }
quri.conjunction
// and
quri.criteria
// [ { field: 'field_1', operator: '==', value: 'my value' } ]

quri = Quri.deserialize({ criteria: [ [ 'field_1', '==', 'my value' ] ] })
quri.toString();
// "field_1".eq("my value")

quri = Quri.deserialize({ criteria: [ { field: 'field_1', operator: '==', value: 'my value' } ] });
quri.toString();
// "field_1".eq("my value")

quri = Quri.deserialize({ conjunction: 'or', criteria: [
  [ 'field_1', '==', 'my value' ],
  [ 'field_2', '==', 'my value 2' ]
] })
quri.toString();
// "field_1".eq("my value")|"field_2".eq("my value 2")

quri = Quri.deserialize({ conjunction: 'or', criteria: [
  { field: 'field_1', operator: '==', value: 'my value' },
  { field: 'field_2', operator: '==', value: 'my value 2' }
] })
quri.toString();
// "field_1".eq("my value")|"field_2".eq("my value 2")

License

MIT © theHarvester

About

JS wrapper for the QURI string specification

Resources

License

Stars

Watchers

Forks

Packages

No packages published