Socket
Socket
Sign inDemoInstall

fast-matcher

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-matcher - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

32

fastMatcher.js
(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 @@

2

package.json
{
"name": "fast-matcher",
"version": "0.1.0",
"version": "0.1.1",
"description": "Find matches fast",

@@ -5,0 +5,0 @@ "main": "fastMatcher.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc