fast-levenshtein
Efficient implementation of Levenshtein algorithm with locale-specific collator support.
Last updated 3 years ago by hiddentao .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fast-levenshtein 
SYNC missed versions from official npm registry.

fast-levenshtein - Levenshtein algorithm in Javascript

Build Status NPM module NPM downloads Follow on Twitter

An efficient Javascript implementation of the Levenshtein algorithm with locale-specific collator support.

Features

  • Works in node.js and in the browser.
  • Better performance than other implementations by not needing to store the whole matrix (more info).
  • Locale-sensitive string comparisions if needed.
  • Comprehensive test suite and performance benchmark.
  • Small: <1 KB minified and gzipped

Installation

node.js

Install using npm:

$ npm install fast-levenshtein

Browser

Using bower:

$ bower install fast-levenshtein

If you are not using any module loader system then the API will then be accessible via the window.Levenshtein object.

Examples

Default usage

var levenshtein = require('fast-levenshtein');

var distance = levenshtein.get('back', 'book');   // 2
var distance = levenshtein.get('我愛你', '我叫你');   // 1

Locale-sensitive string comparisons

It supports using Intl.Collator for locale-sensitive string comparisons:

var levenshtein = require('fast-levenshtein');

levenshtein.get('mikailovitch', 'Mikhaïlovitch', { useCollator: true});
// 1

Building and Testing

To build the code and run the tests:

$ npm install -g grunt-cli
$ npm install
$ npm run build

Performance

Thanks to Titus Wormer for encouraging me to do this.

Benchmarked against other node.js levenshtein distance modules (on Macbook Air 2012, Core i7, 8GB RAM):

Running suite Implementation comparison [benchmark/speed.js]...
>> levenshtein-edit-distance x 234 ops/sec ±3.02% (73 runs sampled)
>> levenshtein-component x 422 ops/sec ±4.38% (83 runs sampled)
>> levenshtein-deltas x 283 ops/sec ±3.83% (78 runs sampled)
>> natural x 255 ops/sec ±0.76% (88 runs sampled)
>> levenshtein x 180 ops/sec ±3.55% (86 runs sampled)
>> fast-levenshtein x 1,792 ops/sec ±2.72% (95 runs sampled)
Benchmark done.
Fastest test is fast-levenshtein at 4.2x faster than levenshtein-component

You can run this benchmark yourself by doing:

$ npm install
$ npm run build
$ npm run benchmark

Contributing

If you wish to submit a pull request please update and/or create new tests for any changes you make and ensure the grunt build passes.

See CONTRIBUTING.md for details.

License

MIT - see LICENSE.md

Current Tags

  • 2.0.6                                ...           latest (3 years ago)

19 Versions

  • 2.0.6                                ...           3 years ago
  • 2.0.5                                ...           3 years ago
  • 2.0.4                                ...           3 years ago
  • 2.0.3                                ...           3 years ago
  • 2.0.2                                ...           3 years ago
  • 2.0.1                                ...           3 years ago
  • 2.0.0                                ...           3 years ago
  • 1.1.4                                ...           3 years ago
  • 1.1.3                                ...           4 years ago
  • 1.1.2                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.7                                ...           4 years ago
  • 1.0.6                                ...           5 years ago
  • 1.0.5                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 976
This Week 41,595
This Month 275,733
Last Day 20,561
Last Week 107,395
Last Month 413,953
Dependencies (0)
None
Dev Dependencies (11)
Dependents (213)

Copyright 2014 - 2016 © taobao.org |