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

special-speller

v1.0.2

Published

Spelling corrector for special words

Downloads

4

Readme

Spelling corrector for special words

NOTE: this package is old and deprecated. Use the new Mistyep package instead.


Check out the demo

Installation

npm install special-speller

Explanation

I wouldn't presume to write a full-fledged spellling corrector when lots of great ones already exist. This is for a more niche case – a rude, crude solution for checking against a bank of obscure or specialized words, or words that could easily be mis-typed. Proper nouns, domain names, and Elvish are all valid use-cases, although at present this spelling corrector is case-insensitive.

It works by computing the edit distance between the input word and the words in the provided "dictionary". But not just any edit distance. It takes into account the physical distances between keys on a keyboard by assigning each key a vector position. The “physical edit distance” (as opposed to traditional Levenshtein distance) is a function of how physically far away each mistyped letter is. As the word bank gets bigger there are bound to be more efficient ways to correct a word's spelling, but this does a fine job of checking off those “quick” and “dirty” boxes.

The JavaScript code is ported from the original Ruby version I wrote while interning at Vouch, and is intended to be easy to plug into an existing site. All you need to do is:

  1. add the npm package, npm install special-speller
  2. set a variable like so: var speller = require('special-speller').specialSpeller, and
  3. get the corrected word like so: var newWord = speller(oldWord, wordBankArray), where oldWord is a string and wordBankArray is the array of strings you want to check against.

Simple use case

In signup fields, there is a high percentage of users who mistype their email address when entering their information. One way to fix this is by offering a "Did you mean ______?" suggestion if a word is close to a known email provider:

var speller = require('special-speller').specialSpeller;
// ...
var suggestion = speller(userEmailInput, ['gmail','hotmail','mail','aol','live','yahoo']);
if (suggestion != userEmailInput) {
    // throw the suggested word to the client
}

In the wild

Check out the code on Flipped Art's signup form, where we use the same instance of speller to check for questionable domain names and questionable TLDs. Try it out by typing [email protected] into the "email" field.

Caveats

  1. The present code doesn't account for capital letters, and by default converts everything to lowercase.
  2. Accented/umlauted letters are in a similar boat with capital letters. Likely the best option would be to build the PHYSICAL_KEYS object with alternate characters that have the same vector position as their non-accented counterparts.
  3. The length-normalizing procedure at the top of physical_edit_distance() is dubious in certain cases. Generally it isn't a problem for the end result, but it could result in some inconsistent behavior if you're trying.