Greater than less
Usage
TODO: Few examples: simple and advanced
API
gtl.filter()
Filter array of numbers with gt rule (alias to greaterThan)
Full list of rules is avalible in "Avaliable rules".
gtl;// => [4, 5]
Filter array of strings
gtl;// => ['a', 'b', 'c']
Filter array of objects through iterator
gtl;// => [{ num : 4 }, { num : 5 }]
Combine rules
You can use multiply rules to filter array:
gtl;// => [3, 4]
You also can use multiply iterator rules:
gtl;// => [{ one: 1, two: 5, three: 4 }, { one: 4, two: 4, three: 9 }]
Avaliable rules
greaterThan (alias: gt)
gtl;// => [4, 5]
greaterThanOrEqualTo (aliases: gte, gteq)
gtl;// => [3, 4, 5]
lessThan (alias: lt)
gtl;// => [1, 2]
lessThanOrEqualTo (aliases: lte, lteq)
gtl;// => [1, 2, 3]
only
gtl;// => [{ num : 1 }, { num : 2 }]
except (alias: not)
gtl;// => [{ num : 2 }, { num : 4 }, { num : 5 }]
grep
Grep array by string:
gtl// => ['my heart', 'hold my tongue']
You also can use RegExp:
gtl// => ['my heart', 'for I must', 'hold my tongue']
Iterator rules
or (alias: in)
You can use in
rule to set fields to search for:
gtl;// => [{ body: { text: 'my heart' } }, { body: { text: 'hold my tongue' } }]
You also can specify multiply fields:
gtl;// => [{ one: 1, two: 5 }, { one: 5, two: 7 }]
and
gtl;// => [{ one: 4, two: 4 }, { one: 5, two: 7 }]
gtl.rules
gtl.rules contain all comparsion rules (lt, gt etc).
You can add your own comparator to gtl.rules:
gtlrules {var isOdd = num % 2 === 1if rulereturn isOdd;elsereturn !isOdd;};
... then:
gtl// => [1, 3, 5]gtl// => [2, 4]
You can't use or
, in
and and
rule name because it's reserved to build-ins iterator rules.
Changelog
This project uses Semantic Versioning for release numbering.
Currently this project in active development but no any releases yet.
Contributors
Idea and code by @kossnocorp.
Check out full list of contributors.
License
The MIT License
Copyright (c) 2012 Sasha Koss
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.