bigbiff | d006b30 | 2015-03-06 18:36:03 -0500 | [diff] [blame] | 1 | module.exports = new FuzzySearchStrategy(); |
2 | |||||
3 | function FuzzySearchStrategy(){ | ||||
4 | var self = this; | ||||
5 | |||||
6 | function createFuzzyRegExpFromString(string){ | ||||
7 | return new RegExp( string.split('').join('.*?'), 'gi'); | ||||
8 | } | ||||
9 | |||||
10 | self.matches = function(string,crit){ | ||||
11 | if( typeof string !== 'string' ) return false; | ||||
12 | string = string.trim(); | ||||
13 | return !!string.match(createFuzzyRegExpFromString(crit)); | ||||
14 | }; | ||||
15 | }; |