1.0.1 • Published 12 months ago

@danny270793/levenshtein v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

Levenshtein

Github pipeline status NPM Type Definitions

install size NPM Unpacked Size GitHub repo size GitHub code size in bytes npm bundle size (scoped)

GitHub commit activity NPM Downloads GitHub Downloads (all assets, all releases)

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

YouTube GitHub LinkedIn

LICENSE

GitHub License

Version

GitHub Tag GitHub Release GitHub package.json version NPM Version

Last update 07/08/2024

1.0.1

12 months ago

1.0.0

12 months ago