🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

didyoumean2

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

didyoumean2

a library for matching human-quality input to a list of potential matches using the Levenshtein distance algorithm

7.0.4
latest
Source
npm
Version published
Weekly downloads
183K
-17.98%
Maintainers
1
Weekly downloads
 
Created

What is didyoumean2?

The didyoumean2 npm package is a utility for suggesting corrections to misspelled words or phrases. It is particularly useful for command-line interfaces, chatbots, and other applications where user input may contain typos. The package uses a combination of string similarity algorithms to provide the best possible suggestions.

What are didyoumean2's main functionalities?

Basic Usage

This feature allows you to provide a list of possible correct words and get suggestions based on the input. In this example, 'appl' is corrected to 'apple'.

const didYouMean = require('didyoumean2');
const input = 'appl';
const suggestions = didYouMean(input, ['apple', 'banana', 'grape']);
console.log(suggestions); // Output: ['apple']

Custom Threshold

This feature allows you to set a custom threshold for the similarity score. The threshold determines how close the input needs to be to the suggestions. In this example, a threshold of 0.4 is used.

const didYouMean = require('didyoumean2');
const input = 'appl';
const options = { threshold: 0.4 };
const suggestions = didYouMean(input, ['apple', 'banana', 'grape'], options);
console.log(suggestions); // Output: ['apple']

Multiple Suggestions

This feature allows you to get multiple suggestions instead of just the best match. In this example, both 'apple' and 'applet' are returned as suggestions for 'appl'.

const didYouMean = require('didyoumean2');
const input = 'appl';
const options = { returnType: 'all-matches' };
const suggestions = didYouMean(input, ['apple', 'applet', 'banana', 'grape'], options);
console.log(suggestions); // Output: ['apple', 'applet']

Other packages similar to didyoumean2

Keywords

closest

FAQs

Package last updated on 17 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts