Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gustf/js-levenshtein
The most efficient JS implementation calculating the Levenshtein distance, i.e. the difference between two strings.
https://github.com/gustf/js-levenshtein
edit-distance levenshtein
Last synced: 4 months ago
JSON representation
The most efficient JS implementation calculating the Levenshtein distance, i.e. the difference between two strings.
- Host: GitHub
- URL: https://github.com/gustf/js-levenshtein
- Owner: gustf
- License: mit
- Created: 2017-05-14T19:43:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-05-10T17:57:41.000Z (over 2 years ago)
- Last Synced: 2024-05-15T15:07:06.095Z (7 months ago)
- Topics: edit-distance, levenshtein
- Language: JavaScript
- Homepage:
- Size: 62.5 KB
- Stars: 444
- Watchers: 5
- Forks: 35
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# js-levenshtein [![Build Status](https://travis-ci.org/gustf/js-levenshtein.svg?branch=master)](https://travis-ci.org/gustf/js-levenshtein)
A very efficient JS implementation calculating the Levenshtein distance, i.e. the difference between two strings.
Based on Wagner-Fischer dynamic programming algorithm, optimized for speed and memory
- use a single distance vector instead of a matrix
- loop unrolling on the outer loop
- remove common prefixes/postfixes from the calculation
- minimize the number of comparisons
- always allocate a new distance vector in order to not leak memory
## Install```
$ npm install --save js-levenshtein
```## Usage
```js
const levenshtein = require('js-levenshtein');levenshtein('kitten', 'sitting');
//=> 3
```## Benchmark
```
$ npm run bench
50 paragraphs, length max=500 min=240 avr=372.5
162 op/s » js-levenshtein
98 op/s » talisman
94 op/s » levenshtein-edit-distance
85 op/s » leven
39 op/s » fast-levenshtein100 sentences, length max=170 min=6 avr=57.5
3,076 op/s » js-levenshtein
2,024 op/s » talisman
1,817 op/s » levenshtein-edit-distance
1,633 op/s » leven
800 op/s » fast-levenshtein2000 words, length max=20 min=3 avr=9.5
3,119 op/s » js-levenshtein
2,416 op/s » talisman
2,141 op/s » levenshtein-edit-distance
1,855 op/s » leven
1,260 op/s » fast-levenshtein
```Benchmarks was performed with node v8.12.0 on a MacBook Pro 15", 2.9 GHz Intel Core i9
## License
MIT © Gustaf Andersson