Closest Match
An NPM module that finds the closest string match or matches in an array using Levenshtein Distance
Installation
npm i closest-match
Usage
const closest_match = require("closest-match");
closest_match.distance(text1, text2)
closest_match.closestMatch(text, array)
closest_match.closestMatch(text, array, true)
Methods
Method | Explanation |
---|
distance(text1, text2) | Returns the Levenshtein difference between the strings. |
closestMatch(text, array, showOccurrences) | Returns the closest match of a specified string in an array. If showOccurrences is true, then it returns an array of all of the closest matches to the string in an array. |
Examples
const { distance, closestMatch } = require("closest-match");
console.log(distance("hlelo", "hello"));
console.log(closestMatch("dag", ["dog", "pumpkin"]));
console.log(closestMatch("hello", ["jello", "yellow", "bello"], true));