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

mistyped

v1.0.1

Published

Get list of all possible words that might have been mistyped

Downloads

5

Readme

A very lightweight package to get list of all possible words that might have been mistyped

NPM Version NPM Downloads PayPal

Installation

Using npm:

$ npm i mistyped

Usage

Suppose a user wants to type tea but instead typed tes. Using this library you can get all possible word combination of tes.

const mistyped = require("mistyped")
const possibleWords = mistyped("tes")

console.log(possibleWords)
// [
//   'tws',
//   'trs',
//   'tss',
//   'tds',
//   'tea',
//   'ted',
//   'tew',
//   'tee',
//   'tez'
// ]

You can see tea also appeared in the list.

This library is NOT based on Levenshtein distance. Instead, it tries to guess the list of most likely words of a mistyped word.

One way to use this library is to merge it with your search engine or pre existing dictionary for better search results.

Note: It only works for QWERTY keyboard and alphabets only.

Another example:

const mistyped = require("mistyped")
const possibleWords = mistyped("ahve", {startAfter: 0})

console.log(possibleWords)
// [
//   'shve', 'qhve',
//   'whve', 'agve',
//   'ajve', 'ayve',
//   'auve', 'abve',
//   'ahce', 'ahbe',
//   'ahge', 'ahvw',
//   'ahvr', 'ahvs',
//   'ahvd', 'have',
//   'ahev'
// ]

You can see have appeared here. We will see later what startAfter means.

API Reference

const mistyped = require("mistyped")


mistyped(word, [options])

| Argument | Type | Required | Description | |----------|------------|----------|-------------------------| | word | string | true | Input word to analyze for mistyping | | options | object | false | Options (see below) |

options object properties:

| Property | Type | Default | Description | |----------|-----------|---------|---------------------------------------------------------------| | startAfter | integer | 1 | Leave number of characters from the beginning. Like for word "coffee", if startAfter is 2 then it will leave "co" and will only take "ffee" for further analysis | | dimension | integer | 2 | Allowed only 3 values 0, 1 and 2. Increasing value means lot more possible words. Play around with this option to know more | | includeMisplaced | boolean | true | Include characters misplaced possibilities. Like "have" may have been typed "ahve". "h" and "a" have been misplaced. |


Usage with options

Use default options for the best results but if you want to explore further, you can play around with it and get results according to your application.

Example: Get only misplaced words

We can just get only misplaced words possibilities by keeping dimension = 0

const mistyped = require("mistyped")
const options = {
  startAfter: 0,
  dimension: 0,
}
const possibleWords = mistyped("ahve", options)

console.log(possibleWords)
// [ 'have', 'ahev' ]

In previous example similar to this, the list was bigger. You can see have appeared here.

similarly you can exclude misplaced words possibilities by keeping includeMisplaced = false

Example: With different startAfter

As mentioned before startAfter starts the analysis after that position and by default its value is chosen to be 1 using this assumption that a user will not make any mistake with the first word while typing. But what if, you want to start the analysis after position 2 and for misplaced words possibilities, you realised it is best to start from the beginning like we did in ahve example. You can achieve this like

const mistyped = require("mistyped")
const word = "ahve"
const optionsExcludeMisplaced = {
  startAfter: 2,
  dimension: 2,
  includeMisplaced: false
}
const optionsMisplacedOnly = {
  startAfter: 0,
  dimension: 0,
  includeMisplaced: true
}
const excludeMisplacedList = mistyped(word, optionsExcludeMisplaced)
const misplacedOnlyList = mistyped(word, optionsMisplacedOnly)

const possibleWords = [...excludeMisplacedList, ...misplacedOnlyList]

console.log(possibleWords)
// [
//   'ahce', 'ahbe',
//   'ahge', 'ahvw',
//   'ahvr', 'ahvs',
//   'ahvd', 'have',
//   'ahev'
// ]

Use it with your search engine

This library is not dependent on any dictionary so it can be used with any word like for example, you have a search engine where you can find a user by its name. While searching for John, suppose it has been mistyped to Johm

const mistyped = require("mistyped")
const possibleWords = mistyped("Johm")

console.log(possibleWords)
// [
//   'jihm', 'jphm',
//   'jkhm', 'jlhm',
//   'jogm', 'jojm',
//   'joym', 'joum',
//   'jobm', 'john',
//   'johk'
// ]

Now search with all these words. John will appear in the search result

Origin Story

Levenshtein distance works amazing but searching is not good because it involves all possibilities which may not be required. Like for example ten and tea has Levenshtein distance 1 but there is very very less chance that tea has been mistyped as ten. This package handles that very well.

License

MIT

Author

Abhishek Khare