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

scatter-rank

v1.0.0

Published

command-t style approximate string matcher as a Node.js function

Downloads

2

Readme

scatter-rank

This is a very similar (identical?) matcher algorighm as behind TextMate's Cmd+T feature, the command-t vim plugin and Emacs Icicles scatter-match completion, as a Node.js library.

Exports a function that looks for a subsequence of a given sequence of characters in an input string, ignoring other characters, and outputs what proportion of that sequence was found, as a number between 0 and 1.

Kind of like /.*a.*b.*c.*/, while counting the longest a-b-c subsequence.

Why

This works great to rank some text items from which a user wants to choose one really quickly by approximately typing it. The heuristic is simple, predictable and tolerates abbreviations and inaccurate typing.

For example, a user might type "nsfudt", and scatter-rank would find that it matches 100% with "node js foundation" (because all the letters are there in the right order), somewhat also with "apache foundation" (because "fudt" is in there) and hardly at all with "wikipedia" (because only the "d" would hit).

Examples

var rank = scatterRank("abcd");

rank("abcd")        // => 1     all OK
rank("abc")         // => 0.75  "d" wasn't found
rank("XYZ")         // => 0     nothing found
rank("gah")         // => 0.25  only "a" found
rank("_a___b_c_d_") // => 1     all OK
rank("dcba")        // => 0.25  only "d" found; rest were out of order
rank("cab")         // => 0.5   "ab" was longest matching subsequence

Alternatively, pass the string to search in as second parameter:

scatterRank("abcd", "i know my abcs") // => 0.75

Related libraries

  • fast-levenshtein is better for ranking mispellings and approximations, but too rigid for abbreviations to match well.

  • string_score is like a fuzzy, more complex version of this. It's better for natural language use-cases where you don't necessarily know much about the string you're looking for. Modifies the String prototype.

  • fuzzy is more complex, can't produce a rank value, and to be honest I don't understand what it does.

  • fuzzy-filter can filter strings for matches and do fancy highlighting stuff, but also can't produce a similarity value.

License

ISC.