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

typo-correction

v1.0.1

Published

Suggest fixing misspelled, typos, matching human-quality input

Downloads

37

Readme

Typo Correction

This library is designed to suggest fixing misspelled words from user input. There are three powerful features in this package:

  • Multiple word checking
  • Giving a list of suggestions
  • A learning feature

DidYouMeanGoogle

You can use it to mimic “Did you mean” from Google Search and correct command lines or specific words before searching.

LIVE Demo and Performance Test

Code Sandbox 🚀

Installation

npm i typo-correction

Usage

import typoCorrection, { typoCorrections } from "typo-correction";
var result = typoCorrection(input,list,learn=[]);
  • input from user
  • list of corrected words
  • learn (optional) list of learning words { in: "", out: "" }

Single word :typoCorrection

var correction = typoCorrection("wuman",["human","woman", "kuman","luman","wonder","winner"...] );
// correction.best -> woman
// correction.matches -> ["human","kuman","luman"] 

Multiple words: typoCorrections

var correction = typoCorrections("wundor wuman",["human","woman", "kuman","luman","wonder","winner"...] );
// correction.best -> wonder woman
// correction.matches -> [[],["human","kuman","luman"]] 

Advanced features

Multiple word checking

In the modern searching system, the position of words does not matter as much as correct spelling does. For example: “wonder woman” and “woman wonder” would give the same result. So, we have designed a solution to correct each word in a string, while the position of words remains.

  • Using typoCorrections to check multiple words.
var correction = typoCorrections("wundor wuman") // correction.best -> wonder woman
var correction = typoCorrections("wuman wonder") // correction.best -> woman wonder 

Giving a list of suggestions

In some cases, we could get more than one correct answer. For example, if a user types “wuman”, it could be “woman” or “human” or "kuman". So, the library will give you the best answer: “woman”. The alternative answers are “human”,"kuman" for the user to select or train the system.

  • Using .matches to get a list of suggestions.
var correction = typoCorrection("wuman",["human","woman", "kuman","luman","wonder","winner"...] );
correction.matches // -> ["human","kuman","luman"] 

Learning feature

Based on different situations, we may have many different suggestions. For better user experiences, a learning function could be used for that purpose. For example, when the user types “wunder wuman”, the answer could be “wander woman”. This way they teach the system that “wonder woman” is a better suggestion. Consequently, the library will suggest “wonder woman” the next time the user searches.

  • Using array of objects {in:"wrong", out:"right"} to modify the result.
var correction = typoCorrections("wunder wuman",[...]);
// correction.best -> wander woman
var correction = typoCorrections("wunder wuman",[...],[{in:"wunder",out:"wonder"}]);
// correction.best -> wonder woman

Performance and Quality

By using the Levenshtein algorithm with our research on user behaviors, this library would give users an extremely fast solution and accuracy in most cases. You can test the performance live at this link. 🚀 CodeSandbox 🚀

Thank you

I am thankful for the algorithm of Mr. Vladimir Levenshtein. I appreciate developer Hiddentao for developing “fast-levenshtein”, which is used as a dependency of this library.

Happy coding

Dev9x