Bakhtina Sofya 441b76b729 first commit | 3 minggu lalu | |
---|---|---|
.. | ||
LICENSE.md | 3 minggu lalu | |
README.md | 3 minggu lalu | |
levenshtein.js | 3 minggu lalu | |
package.json | 3 minggu lalu |
An efficient Javascript implementation of the Levenshtein algorithm with locale-specific collator support.
Install using npm:
$ npm install fast-levenshtein
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.
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
To build the code and run the tests:
$ npm install -g grunt-cli
$ npm install
$ npm run build
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
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.
MIT - see LICENSE.md