Array filtering for node.js and the browser inspired by MongoDB.
Filtr is available on npm.
npm install filtr
A browser build is available in the repository's
Download the package and include either the normal or minimized build in your HTML header.
The browser build is fully AMD and CommonJS compatible and should work on all browser.
Filtr is still in early development so expect this list to grow.
filtr.getPathValuereturns the nested value in an object given a string path
filtr.comparatorsare available directly for quick value testing
var query = filtr $gt: 15 $lt: 25results = querytest 5 10 17 19 25 ;// results == [ 17, 19 ];
Testing also supports a number of options passed in as the second argument.
spec output modifier is an easy way to handle post processing of result sets
without having to match up a subset.
var query = filtr $gt: 15 $lt: 25results = querytest 5 10 17 19 25 spec: 'boolean' ;// results == [ false, false, true, true, false ];
var dataComplex =a: b: 100c: 'testC'd:e: 'world'a: b: 50c: 'testC'd:e: 'universe'e: 'galaxy';var query1 = filtr 'a.b': $gt: 75 $lt: 125 ;query2 = filtr 'a.b': $gt: 25 $lt: 75 'd.e': $eq: 'universe' ;var res1 = query1testdataComplex // result would have the first itemres2 = query1testdataComplex; // result would have the second item
A helper is also available that returns the value in a nested object given a string path.
var hello = filtrgetPathValue'd.e' dataComplex1;// hello == 'universe'
Please post issues to GitHub Issues.
A browser suite is also available at
test/browser/index.js. The same test definitions are
used in both contexts.
Interested in contributing? Fork to get started. Contact @logicalparadox if you are interested in being regular contributor.
(The MIT License)
Copyright (c) 2011-2012 Jake Luer email@example.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.