@danny270793/levenshtein
v1.0.1
Published
library to measure levenshtein distance between words
Downloads
7
Readme
Levenshtein
Library to compute levenshtein distance between strings and find more similar phrase in a list
Instalation
Install package from public registry
npm install @danny270793/levenshtein
Examples
Compute the levenshtein distance between two strings
import Levenshtein from '@danny270793/levenshtein'
const referenceWord: string = 'danny'
const valueToCompare: string = 'danni'
const computePercentage: number = Levenshtein.computePercentage(
referenceWord,
valueToCompare
)
console.log(computePercentage)
You can customize thw weight of each type of change in a word specifying costs
import Levenshtein, { Costs } from '@danny270793/levenshtein'
const referenceWord: string = 'danny'
const valueToCompare: string = 'danni'
const costs: string = { inserts: 0, updates: 1, deletes: 0 }],
const computePercentage: number = Levenshtein.computePercentage(
referenceWord,
valueToCompare,
costs
)
console.log(computePercentage)
You can provide a list of values options
to detect which is more similar to and specific word matching
import Levenshtein, { Costs, BestMatch } from '@danny270793/levenshtein'
const options: string[] = ['danni', 'danniel', 'dani']
const matching: string = 'danny'
const bestMatch: BestMatch = Levenshtein.getBestMatch(
options,
matching
)
console.log(`more similar string ${bestMatch.text}`)
console.log(`levenshtein distance of the more similar ${bestMatch.match}`)
Follow me
LICENSE
Version
Last update 07/08/2024