Skip to content

A lightweight TypeScript library to calculate Damerau-Levenshtein edit distance and suggest similar strings.

License

Notifications You must be signed in to change notification settings

dep-ts/edit-distance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@dep/edit-distance 📝

A lightweight TypeScript library to calculate Damerau-Levenshtein edit distance and suggest similar strings.

JSR version

Features ✨

  • 🧮 Calculate the minimum number of operations to transform one string into another
  • 🔍 Suggest similar words based on edit distance
  • ⚡ Supports insertions, deletions, substitutions, and adjacent transpositions
  • 🌐 Works with multiple languages and normalizes accented characters
  • 🛠️ Fully typed with TypeScript for modern development

Installation 📦

  • Deno:

    import { editDistance, suggestSimilar } from 'jsr:@dep/edit-distance';
  • Node.js (18+) or Browsers:

    npx jsr add @dep/edit-distance

Then import as an ES module:

import { editDistance, suggestSimilar } from '@dep/edit-distance';

Usage 🎯

CLI 💻

If using in a CLI tool, you can integrate suggestSimilar for command suggestions:

$ mycli chekcout
(Did you mean checkout?)

API 🧩

Basic examples:

import { editDistance, suggestSimilar } from '@dep/edit-distance';

const dist = editDistance('form', 'from');
console.log(dist); // 1 (transposition counted)

const suggestion = suggestSimilar('checikout', [
  'checkout',
  'checkin',
  'checkup',
]);
console.log(suggestion);
// "\n(Did you mean checkout?)"

License 📄

MIT License – see LICENSE for details.

Author: Estarlin R (estarlincito.com)

About

A lightweight TypeScript library to calculate Damerau-Levenshtein edit distance and suggest similar strings.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published