Skip to main content
Module

std/text/mod.ts>closestString

The Deno Standard Library
Go to Latest
function closestString
import { closestString } from "https://deno.land/std@0.223.0/text/mod.ts";

get most-similar word

Examples

Example 1

import { closestString } from "https://deno.land/std@0.223.0/text/closest_string.ts";

const possibleWords: string[] = ["length", "size", "blah", "help"];

// case-insensitive by default
const word = closestString("hep", possibleWords);

Parameters

givenWord: string
  • The string to measure distance against
possibleWords: string[]
  • The string-array that will be sorted
optional
options: { caseSensitive?: boolean; }
  • Flag indicating whether the distance should include case. Default is false.

Returns

string

A sorted copy of possibleWords