npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

scored-fuzzysearch

v1.0.5

Published

Tiny and blazing-fast fuzzy search in JavaScript

Downloads

247

Readme

scored-fuzzysearch

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.

This was forked from https://github.com/bevacqua/fuzzysearch to add case insensitivity and scored results

Install

From npm

npm install --save fuzzysearch

fuzzysearch(needle, haystack)

Returns number (score value where a larger score represents a better match and 0 is no match) 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 matches.

const { fuzzysearch, findMatchIndices } = require("scored-fuzzysearch");

fuzzysearch("cwhEE", "cartwheel"); // 0.999994902390217
fuzzysearch("crtw", "cartwheel"); // 0.9997958927178325
fuzzysearch("CWe", "cartwheel"); // 0.9971004280869964
fuzzysearch("eel", "cartwheel"); // 0.9871677449104073
fuzzysearch("ee", "cartwheel"); // 0.985984563434286
fuzzysearch("eeel", "cartwheel"); // 0
fuzzysearch("dog", "cartwheel"); // 0

and to get match indices

findMatchIndices("arhel", "cartwheel");

returns

[
  { start: 1, length: 2 },
  { start: 5, length: 2 },
  { start: 8, length: 1 },
];

Scoring is based on

  1. how many characters match
  2. how close the initial match character is to the beginning of the test string
  3. how many characters match without spacing
  4. how close multiple match segments are to eachother