New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fuzzysearch

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fuzzysearch - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

6

CHANGELOG.md

@@ -0,5 +1,9 @@

# v1.0.3 Short Fuse
- Improved circuit-breaker when `needle` and `haystack` length are equal
# v1.0.2 Vodka Tonic
- Slightly updated circuit-breaker that tests for equal length first
- Doubled method performance
- Doubled method performance ([see jsperf tests](http://jsperf.com/fuzzysearch-regex/3))

@@ -6,0 +10,0 @@ # v1.0.1 Circuit Breaker

14

index.js
'use strict';
function fuzzysearch (query, text) {
var tlen = text.length;
var qlen = query.length;
function fuzzysearch (needle, haystack) {
var tlen = haystack.length;
var qlen = needle.length;
if (qlen > tlen) {
return false;
}
if (qlen === tlen && query === text) {
return true;
if (qlen === tlen) {
return needle === haystack;
}
outer: for (var i = 0, j = 0; i < qlen; i++) {
var qch = query.charCodeAt(i);
var nch = needle.charCodeAt(i);
while (j < tlen) {
if (text.charCodeAt(j++) === qch) {
if (haystack.charCodeAt(j++) === nch) {
continue outer;

@@ -17,0 +17,0 @@ }

{
"name": "fuzzysearch",
"description": "Fuzzy search in JavaScript",
"version": "1.0.2",
"description": "Tiny and blazing-fast fuzzy search in JavaScript",
"version": "1.0.3",
"homepage": "https://github.com/bevacqua/fuzzysearch",

@@ -6,0 +6,0 @@ "author": {

# fuzzysearch
> Fuzzy search in JavaScript
> Tiny and blazing-fast fuzzy search in JavaScript
Fuzzy searching allows for flexibly matching a string with partial input, useful for filtering data very quickly based on lightweight user input.
# Demo
To see `fuzzysearch` in action, head over to [bevacqua.github.io/horsey][3], which is a demo of an autocomplete component that uses `fuzzysearch` to filter out results based on user input.
# Install

@@ -15,5 +19,5 @@

# `fuzzysearch(query, data)`
# `fuzzysearch(needle, haystack)`
Returns `true` if `query` matches `data` using a fuzzy-searching algorithm.
Returns `true` if `needle` matches `haystack` using a fuzzy-searching algorithm. Note that this program doesn't implement _[levenshtein distance][2]_, but rather a simplified version where **there's no approximation**. The method will return `true` only if each character in the `needle` can be found in the `haystack` and occurs after the preceding character.

@@ -30,4 +34,14 @@ ```js

An exciting application for this kind of algorithm is to filter options from an autocomplete menu, check out [horsey][3] for an example on how that might look like.
# But! _`RegExp`s...!_
![chart showing abysmal performance for regexp-based implementation][1]
# License
MIT
[1]: https://cloud.githubusercontent.com/assets/934293/6495796/106a61a6-c2ac-11e4-945d-3d1bb066a76e.png
[2]: http://en.wikipedia.org/wiki/Levenshtein_distance
[3]: http://bevacqua.github.io/horsey
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