Skip to content

Calculate the Damerau–Levenshtein distance between strings.

License

Notifications You must be signed in to change notification settings

el3um4s/Damerau-Levenshtein

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Damerau-Levenshtein

GitHub license GitHub tag HitCount deno doc deno.land

Calculate the Damerau–Levenshtein distance between strings.

Usage

Call to "distance" functions outputs an integer, the calculated Damerau-Levenshtein distance between 2 strings given as parameters. If the result is 0, strings are identical. The higher the result, the less similar strings are.

import { distance } from "https://deno.land/x/damerau_levenshtein/mod.ts";

const firstString: string = "Hello";
const secondString: string = "Hello World";

const d = distance(firstString, secondString);

console.log(
  `Damerau–Levenshtein distance between "${firstString}" and "${secondString}" is: ${d} `,
);

There are 1 demo available. The first demo queries Wikipedia and print the first result

deno run .\demo.ts "Hello Wordl" "Hello world"

You can run the demo directly from the repository with the commands:

deno run https://deno.land/x/damerau_levenshtein/demo.ts  "Hello Wordl" "Hello world"

I was inspirated by fabvalaaah's repository damerau-levenshtein-js

API

  • function compareDistance(a: StringWithDistance, b: StringWithDistance): number : Compare distance between 2 words (format like StringWithDistance).
  • function distance(a: string, b: string) : Get the Damerau-Levenshtein distance between 2 strings
  • function distanceDamerau(string: string, compared: string): StringWithDistance : Return an object with string, compared string and distance beetween
  • function distanceList(target: string, list: Array): Array : Return an arry of StringWithDistance with the distance from the compared string
  • function minDistance(string: string, list: Array): number : Get the minimum Damerau-Levenshtein distance between a string and an array of strings
  • function sortByMinDistance(list: Array): Array : Return an arry of StringWithDistance sorted by min distance
  • function sortWordByMinDistance(target: string, list: Array): Array : Return an arry of StringWithDistance sorted by min distance
  • interface StringWithDistance : Interface for string, compared string and distance beetween