fast-matcher
Advanced tools
Comparing version 0.1.0 to 0.1.1
(function() { | ||
/** | ||
* @example | ||
* var list = ['b', 'a', 'c']; | ||
* | ||
* // constructing a FastMatcher instance should not modify the list passed in | ||
* new FastMatcher(list); // list == ['b', 'a', 'c'] | ||
*/ | ||
function FastMatcher(list, options) { | ||
this.list = list; | ||
this.list = list.slice(0); | ||
this.options = options || {}; | ||
@@ -30,4 +37,10 @@ this.matches = this.options.matches || []; | ||
FastMatcher.prototype.createSelector = function createSelector() { | ||
var selector = this.options.selector; | ||
var baseSelector = this.getBaseSelector(this.options.selector); | ||
return this.options.caseInsensitive ? | ||
function(x) { return baseSelector(x).toLowerCase(); } : | ||
baseSelector; | ||
}; | ||
FastMatcher.prototype.getBaseSelector = function(selector) { | ||
if (typeof selector === 'function') { | ||
@@ -46,5 +59,11 @@ return selector; | ||
* @example | ||
* var fm = new FastMatcher(['ab', 'ac', 'ba', 'bc']); | ||
* function getMatches(list, prefix, options) { | ||
* return new FastMatcher(list, options).getMatches(prefix); | ||
* } | ||
* | ||
* fm.getMatches('a'); // => ['ab', 'ac'] | ||
* getMatches(['aa', 'ab', 'ba', 'bb'], 'a'); | ||
* // => ['aa', 'ab'] | ||
* | ||
* getMatches(['aa', 'ba', 'AB', 'BB'], 'a', { caseInsensitive: true }); | ||
* // => ['aa', 'AB'] | ||
*/ | ||
@@ -126,2 +145,5 @@ FastMatcher.prototype.getMatches = function getMatches(prefix) { | ||
* @example | ||
* startsWith('', 'a'); // => false | ||
* startsWith('a', 'a'); // => true | ||
* startsWith('aa', 'a'); // => true | ||
* startsWith('foo', 'f'); // => true | ||
@@ -133,3 +155,3 @@ * startsWith('bar', 'f'); // => false | ||
function startsWith(string, prefix) { | ||
return string.lastIndexOf(prefix, prefix.length) === 0; | ||
return string.lastIndexOf(prefix, prefix.length - 1) === 0; | ||
} | ||
@@ -136,0 +158,0 @@ |
{ | ||
"name": "fast-matcher", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Find matches fast", | ||
@@ -5,0 +5,0 @@ "main": "fastMatcher.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13063
209