You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					25 lines
				
				479 B
			
		
		
			
		
	
	
					25 lines
				
				479 B
			| 
								 
											4 years ago
										 
									 | 
							
								'use strict';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								function fuzzysearch (needle, haystack) {
							 | 
						||
| 
								 | 
							
								  var tlen = haystack.length;
							 | 
						||
| 
								 | 
							
								  var qlen = needle.length;
							 | 
						||
| 
								 | 
							
								  if (qlen > tlen) {
							 | 
						||
| 
								 | 
							
								    return false;
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  if (qlen === tlen) {
							 | 
						||
| 
								 | 
							
								    return needle === haystack;
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  outer: for (var i = 0, j = 0; i < qlen; i++) {
							 | 
						||
| 
								 | 
							
								    var nch = needle.charCodeAt(i);
							 | 
						||
| 
								 | 
							
								    while (j < tlen) {
							 | 
						||
| 
								 | 
							
								      if (haystack.charCodeAt(j++) === nch) {
							 | 
						||
| 
								 | 
							
								        continue outer;
							 | 
						||
| 
								 | 
							
								      }
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    return false;
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								  return true;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								module.exports = fuzzysearch;
							 |