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

spelt

v0.0.3

Published

Fast spellchecker written in javascript

Downloads

239

Readme

Spelt

JavaScript english spellchecker written in TypeScript.

Demo: http://spelt-demo.surge.sh/

Installation

Install the spell checker via NPM

npm i --save spelt

Install one of the dictionaries

  • British English dictionary
npm i --save spelt-gb-dict
  • American English dictionary
npm i --save spelt-us-dict
  • Canadian English dictionary
npm i --save spelt-ca-dict
  • Australian English dictionary
npm i --save spelt-au-dict

Usage

// import the lib
import spelt from "spelt";
// import one of the dictionaries
import {dictionary} from "spelt-gb-dict";
// build dictionary
const check = spelt({
	dictionary:dictionary,
	// can be either "gb" or "us"
	distanceThreshold:0.2
	// when a correction found with this distance
	// we'll stop looking for another
	// this would improve performance
});

console.log(check("heve"));

The above code would output:

{
	// the raw input
	raw:"heve",
	// correct or not
	correct:false
	// corrections array sorted by string distance
	[
		{
			// possible correction
			correction:"have",
			// distance from the input word
			distance:0.4
		},
		// .... other possible corrections
	]
}

How it works

how it works

String Distance

I've noticed that a lot of spellcheckers are using the levenshtein distance (LD), I don't think it's the appropriate solution, since it doesn't take moving a two letters around in consideration.

For example:

  1. the distance between abcde and abcxx is 2.
  2. the distance between abcde and abced is also 2.

But on the first case we introduced two new letters, and removed two letters! while on the second case we just moved the e and d around without introducing or removing any letter.

So in short, I don't see the levenshtein distance as an appropriate solution for a spellchecker.

I've wrote my own string distance calculator and you can find it here.

Performance

  • Spellchecking a book: Processing H.G Wells Novel The Time Machine with (1000s of misspellings introduced took about 8 seconds), in a rate of 4K words/second.
  • Spellchecking Wikipedia list: Processing about 4 thousands words, all misspelt, took about 3.5 seconds with a rate of 2.3K word/second.

This is not very impressive, but I'm working on it. However, it's far better than Norvig's spellchecker.

Accuracy

Running on wikipedia's list, with a distance threshold of 0, It was able to find the accurate correction in the first 5 suggestions on 85% of the cases.

License

The MIT License