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

bounded-levenshtein

v0.0.1

Published

Super-fast Levenshtein edit distance with a maximum

Downloads

3

Readme

bounded-levenshtein

Find the maximum distance between two JavaScript Strings, or Infinity.

Sources

  • Wikipedia
  • Talisman, which is faster for tiny strings but is always packaged as four functions instead of one.
  • js-levenshtein, which has great benchmarks and is super-fast for small strings but doesn't accept a maxDistance and therefore has maximum running time O(aLength * bLength) instead of ours, O(max(aLength, bLength) * maxDistance).

This module's bench.js is stolen from js-levenshtein.

We ought to steal js-levenshtein's loop-unrolling idea. (It compares four characters at a time.) Right now we're simpler than that.

Benchmark

Benchmarked on 2018-08-27 on an Intel i7-4650U:

bounded-levenshtein (master *>)$ npm run bench
> [email protected] bench /home/adam/src/cjworkbench/bounded-levenshtein
> matcha bench.js
                      50 paragraphs, length max=500 min=240 avr=372.5
         326,508 op/s » bounded-levenshtein
             100 op/s » js-levenshtein
         162,595 op/s » talisman
              59 op/s » levenshtein-edit-distance
              53 op/s » leven
              36 op/s » fast-levenshtein
                      100 sentences, length max=170 min=6 avr=57.5
          62,220 op/s » bounded-levenshtein
           1,936 op/s » js-levenshtein
          28,112 op/s » talisman
           1,191 op/s » levenshtein-edit-distance
           1,101 op/s » leven
             780 op/s » fast-levenshtein
                      2000 words, length max=20 min=3 avr=9.5
           1,254 op/s » bounded-levenshtein
           2,130 op/s » js-levenshtein
           1,462 op/s » talisman
           1,351 op/s » levenshtein-edit-distance
           1,460 op/s » leven
           1,208 op/s » fast-levenshtein
  Suites:  3
  Benches: 18
  Elapsed: 18,250.62 ms

In short: bounded-levenshtein runs much faster in the worst case. That makes it safer to use when you don't know much about what the input will be.

Developing

npm install
npm test -- --watch             # runs tests continuously
npm run-script build -- --watch # builds continuously
npm run bench                   # benchmark!

Pick a feature; write a test; make it pass; commit.

Deploying

  1. Update version in package.json
  2. npm install to update package-lock.json
  3. git commit -am 'vx.x.x && git tag vx.x.x && git push && git push origin vx.x.x
  4. npm publish