weighted-damerau-levenshtein
v0.2.1
Published
Weighted Damerau-Levenshtein and Levenshtein edit distance for Node.js with configurable operation costs.
Downloads
5,762
Maintainers
Readme
Weighted Damerau-Levenshtein Distance for Node.js
Weighted Damerau-Levenshtein and Levenshtein edit distance with configurable operation costs. Useful for typo tolerance, fuzzy matching, search ranking, and query correction in TypeScript/JavaScript/Node.js.
Install
npm install weighted-damerau-levenshteinRequires Node.js 20 or newer.
Why this package
- Configurable insertion, deletion, and substitution weights
- Optional transposition support (
useDamerau: true/false) - Runtime input validation for safer production usage
- Zero runtime dependencies
- Included TypeScript declarations (
index.d.ts)
Usage
const distance = require('weighted-damerau-levenshtein');
// Weighted Damerau-Levenshtein
const a = distance('hello word', 'Hello World!');
// 4 (two substitutions + two insertions)
// Lower insertion cost
const b = distance('hello word', 'Hello World!', { insWeight: 0.5 });
// 3
// Classic Levenshtein (Damerau disabled)
const c = distance('Hi there', 'Hi tehre', { useDamerau: false });
// 2TypeScript
This package ships with built-in type declarations (index.d.ts).
import distance = require('weighted-damerau-levenshtein');
const score: number = distance('kitten', 'sitting', {
insWeight: 1,
delWeight: 1,
subWeight: 1,
useDamerau: true,
});API
distance(source, target, options?) => number
Options:
insWeight(number, default1)delWeight(number, default1)subWeight(number, default1)useDamerau(boolean, defaulttrue)
Validation behavior:
sourceandtargetmust be strings- Weights must be finite numbers greater than or equal to
0 useDameraumust be a boolean- Unknown option keys throw a
TypeError
Development
npm install
npm run ci
npm run pack:checknpm run verify runs lint + tests on any supported Node version.npm run test:coverage enforces strict 100% coverage thresholds (used in CI on Node 22).
Release
- CI runs in GitHub Actions from
.github/workflows/ci.yml - CI matrix runs
verifyon Node 20/22/24, with Node 25 as a non-blocking smoke check - Strict 100% coverage enforcement runs on Node 22 and 24
- Publishing runs from
.github/workflows/publish.ymlon semver tags (vX.Y.Z) npm publish --provenancerequires repositoryNPM_TOKENand npm publisher setup
License
Licensed under Apache 2.0. See LICENSE.
