
Product
Announcing Socket Certified Patches: One-Click Fixes for Vulnerable Dependencies
A safer, faster way to eliminate vulnerabilities without updating dependencies
ts-levenshtein
Advanced tools
Efficient implementation of Levenshtein algorithm with locale-specific collator support.
A TypeScript implementation of the Levenshtein algorithm with locale-specific collator support. The core is an internal Myers bit‑parallel implementation (no external runtime dependency), with small‑string DP fast path and typed‑array buffer reuse.
npm install ts-levenshtein
CDN
You can load either the global IIFE build or ESM via esm.sh.
TSLevenshtein):
https://cdn.jsdelivr.net/npm/ts-levenshtein/dist/index.global.jshttps://unpkg.com/ts-levenshtein/dist/index.global.jshttps://esm.sh/ts-levenshteinDefault usage (Node.js)
// CommonJS (npm)
const levenshtein = require("ts-levenshtein").default;
console.log(levenshtein.get("back", "book")); // 2
console.log(levenshtein.get("我愛你", "我叫你")); // 1
// or ESM
// import levenshtein from 'ts-levenshtein'
// console.log(levenshtein.get('back', 'book'))
Browser via CDN (IIFE)
<script src="https://cdn.jsdelivr.net/npm/ts-levenshtein/dist/index.global.js"></script>
<script>
// Global name: TSLevenshtein
const d1 = TSLevenshtein.default.get('kitten', 'sitting');
const d2 = TSLevenshtein.default.get('我愛你', '我叫你');
console.log(d1, d2);
// If you prefer unpkg:
// <script src="https://unpkg.com/ts-levenshtein/dist/index.global.js"></script>
// Note: CDN availability depends on publishing to npmjs.
// Optional: ESM via CDN loaders may vary by toolchain.
</script>
Browser via CDN (ESM with esm.sh)
<script type="module">
import levenshtein from 'https://esm.sh/ts-levenshtein?bundle';
console.log(levenshtein.get('kitten', 'sitting'));
console.log(levenshtein.get('我愛你', '我叫你'));
// Tip: `?bundle` helps ensure a single file for browsers
// Deno: import levenshtein from 'https://esm.sh/ts-levenshtein'
</script>
Locale-sensitive string comparisons
It supports using Intl.Collator for locale-sensitive string comparisons:
// CommonJS (npm)
const levenshtein = require("ts-levenshtein").default;
levenshtein.get("mikailovitch", "Mikhaïlovitch", { useCollator: true });
// 1
// or ESM
// import levenshtein from 'ts-levenshtein'
// levenshtein.get('mikailovitch', 'Mikhaïlovitch', { useCollator: true })
dist/index.cjsdist/index.mjsdist/index.umd.jsdist/index.global.js (global TSLevenshtein)dist/index.d.ts (exposed via "types" field)To build the code and run the tests:
npm install
npm run build
npm test
Internals:
Uint16Array/Int32Array) and fixed‑capacity buffer reuse to minimize allocationsRun the included benchmark:
npm run benchmark
Results vary by machine/Node version; expect competitive performance while keeping correctness and zero external deps.
Sample run (lower is faster):
Environment: Apple M4 MacBook, Node.js 22
| Rank | Implementation | Time (ms) | Relative to fastest | Status |
|---|---|---|---|---|
| 1 | ts-levenshtein | 0.71 | 0.00% | ok |
| 2 | levenshtein-edit-distance | 1.82 | 156.34% | ok |
| 3 | levenshtein | 2.57 | 261.97% | ok |
| 4 | levenshtein-component | 3.18 | 347.89% | ok |
| 5 | levenshtein-deltas | 4.04 | 469.01% | ok |
| 6 | natural | 14.41 | 1929.58% | ok |
If you wish to submit a pull request, please update and/or create new tests for any changes you make and ensure the build and tests pass locally (npm run build, npm test).
See CONTRIBUTING.md for details.
MIT - see LICENSE.md
1.0.7 (2025-08-15)
FAQs
Efficient implementation of Levenshtein algorithm with locale-specific collator support.
We found that ts-levenshtein demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies

Product
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.

Research
/Security News
Malicious npm packages use Adspect cloaking and fake CAPTCHAs to fingerprint visitors and redirect victims to crypto-themed scam sites.