closestString
import { closestString } from "jsr:@ende/text";function
function closestString(givenWord: string, possibleWords: ReadonlyArray<string>, options?: ClosestStringOptions): stringFinds the most similar string from an array of strings.
By default, calculates the distance between words using the Levenshtein distance.
givenWord: stringThe string to measure distance against
possibleWords: ReadonlyArray<string>The string-array to pick the closest string from
options?: ClosestStringOptionsThe options for the comparison.
Returns
The closest string
Example: Usage
import { closestString } from "@ende/text/closest-string";
import { assertEquals } from "@ende/assert";
const possibleWords = ["length", "size", "blah", "help"];
const suggestion = closestString("hep", possibleWords);
assertEquals(suggestion, "help");