Skip to content
Find objects in an array by regex or attribute value
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
.gitignore
Makefile
index.js
package.json
readme.md
specs.js

readme.md

Kwery

Find objects in an array or tree structure by regex or attribute value. All values get converted to a RegExp.

Flat

var objects = [ { name: 'one' }, { name: 'two' }, { name: 'three' } ];

var result = kwery.flat(objects, { name: 'one' });

// or

var result = kwery.flat(objects, { name: /.*/ });

result.many(function (data) {
  // data: array
});

result.one(function (data) {
  // called when there is atleast one result
});

result.empty(function () {
  // called when result is empty
});

Tree

var db = [
  {
    id: 0,
    name: 'snowboard',
    path: '/snowboard',
    children: [
      {
        id: 1,
        name: 'tags',
        path: '/snowboard/tags',

        children: [
          { id: 2, name: 'red', path: '/snowboard/tags/red' },
          { id: 3, name: 'green', path: '/snowboard/tags/green' }
        ]

      }
    ]
  }
];

var result = kwery.tree(db, { path: /snowboard\/.*/ });

result.many(function (data) {
  // data: array
});

result.one(function (data) {
  // called when there is atleast one result
});

result.empty(function () {
  // called when result is empty
});

Test

mocha.js and should.js is needed.

make test
Something went wrong with that request. Please try again.