loopback-filters
This module implements LoopBack style filtering without any dependencies on
LoopBack.
Install
$ npm install loopback-filters
Usage
Below is a basic example using the module
var applyFilter = require('loopback-filters');
var data = [{foo: 'bar'}, {bat: 'baz'}, {foo: 'bar'}];
var filter = {where: {foo: 'bar'}};
var filtered = applyFilter(data, filter);
console.log(filtered);
The output would be:
[{foo: 'bar'}, {foo: 'bar'}]
Features
Where
applyFilter({
where: {
price: {gt: 10, lt: 100},
category: {like: '.* Shoes'},
status: {inq: ['in-stock', 'available']}
}
})
Only include objects that match the specified where clause. See full list of supported operators.
Geo Filter / Near
applyFilter(data, {
where: {
location: {near: '153.536,-28'}
},
limit: 10
})
Sort objects by distance to a specified GeoPoint
.
Order
Sort objects by one or more properties.
Limit / Skip
Limit the results to a specified number. Skip a specified number of results.
Fields
Include or exclude a set of fields in the result.
Note: Inclusion from loopback is not supported!
Docs
See the LoopBack docs for the filter syntax.