fastest-levenshtein
The fastest JavaScript/TypeScript implementation of Levenshtein edit distance
Repository Health
Technical Analysis
fastest-levenshtein is a zero-dependency JavaScript/TypeScript library that computes the Levenshtein edit distance between two strings faster than any other published JS implementation, according to its own benchmark suite against js-levenshtein, leven, fast-levenshtein, and others. It exposes two functions: distance() for the raw edit-distance number, and closest() for finding the string in an array with the smallest edit distance to a target.
The entire implementation lives in a single TypeScript file (mod.ts) with no runtime dependencies, and ships prebuilt CommonJS and ESM outputs alongside .d.ts type declarations. It works identically under Node.js and Deno, making it a drop-in choice anywhere fuzzy string matching, spell-check suggestion, or typo-tolerant search needs a fast core distance metric.
What You Get
- A
distance(a, b)function returning the Levenshtein edit distance between two strings - A
closest(target, candidates)function returning the candidate string with the smallest edit distance to the target - Zero runtime dependencies and a small single-file implementation, keeping install and parse cost minimal
- Prebuilt CommonJS and ESM builds plus TypeScript type declarations out of the box
- Published benchmarks showing consistently higher ops/sec than js-levenshtein, leven, fast-levenshtein, and levenshtein-edit-distance across string lengths from N=4 to N=1024
Common Use Cases
- Typo-tolerant search or autocomplete: ranking candidate strings by similarity to a user’s query
- Spell-check suggestion engines that need to find the closest dictionary word to a misspelled input
- Fuzzy matching of user input against a fixed set of commands, tags, or identifiers
- Deduplication or record-linkage pipelines that score near-duplicate strings by edit distance
Under The Hood
Architecture - The library is a single TypeScript source file, mod.ts (142 lines), exporting exactly two functions: distance and closest. There is no class hierarchy, no configuration object, and no plugin surface — the entire public API is these two pure functions operating on strings and arrays of strings. closest is implemented as a thin wrapper that iterates candidates and calls distance for each, tracking the minimum. Tech Stack - Written in TypeScript, compiled to both CommonJS (mod.js) and ESM (esm/mod.js) via tsc, with a separate tsconfig.esm.json for the ESM build target. It has zero runtime dependencies; devDependencies are limited to TypeScript, Jest for testing, ESLint/Prettier for linting, and several competing Levenshtein implementations (fast-levenshtein, js-levenshtein, leven, natural, talisman) pulled in purely to drive the comparative benchmark suite (bench.ts). Code Quality - Tests exist under test.ts and run via Jest with coverage reporting wired to Coveralls in CI. Given the algorithm’s narrow, well-defined scope (a single numeric function plus a thin wrapper), the surface area for bugs is small; the codebase favors dense, optimized loop logic over abstraction, which is typical and appropriate for a performance-focused micro-library. Repository activity has been low in recent years (last push 2024-03), consistent with a small utility that reached feature-complete maturity rather than one that is unmaintained by neglect. API Design - Getting started requires a single import and a single function call — distance('fast', 'faster') — with no configuration, options object, or setup step. This minimalism is the library’s main developer-experience strength: it does exactly one thing and exposes exactly the two functions needed to do it, in both Node and Deno without any adapter code.
Used by 9 apps in this directory
Continue
Developer Tools · AI Development · AI Code Assistants
Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.
Karakeep
Bookmarks Archiving
Self-hosted bookmark manager that captures links, notes, images, and PDFs with AI tagging, full-text search, and automatic archiving.
Kibana
Analytics · Monitoring
Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.
Langfuse
AI Development · Monitoring
Open source AI engineering platform for LLM observability, prompt management, evaluation, and debugging — self-host in minutes or use Langfuse Cloud.
Lightdash
Analytics · Data Engineering
The open-source Looker alternative that turns your dbt project's metrics and dimensions into governed, self-serve charts and dashboards — no license key required.
Mastra Code
AI Code Assistants
"A coding agent that never compacts" — a terminal-based AI coding agent built on the Mastra framework, with Observational Memory instead of context compaction, multi-model support, and OAuth login for Claude Max or ChatGPT Plus.
n8n
Automation · No Code Platforms
Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.
Promptfoo
AI Development
An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.
RelayPlane
AI Agents
An npm-native, drop-in LLM proxy for Node.js — swap in as your OpenAI/Anthropic base URL to get per-request cost tracking, task-aware routing, budget enforcement, and anomaly detection running locally, for free.