fast-levenshtein

Efficient Javascript implementation of Levenshtein algorithm with locale-specific collator support.

  • 所有者: hiddentao/fast-levenshtein
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

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 comparisons 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.

CDN

The latest version is now also always available at https://npm-cdn.com/pkg/fast-levenshtein/

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

主要指標

概覽
名稱與所有者hiddentao/fast-levenshtein
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2013-04-17 05:57:55
推送於2021-10-03 19:03:31
最后一次提交2020-07-22 15:29:13
發布數16
最新版本名稱3.0.0 (發布於 )
第一版名稱1.0.1 (發布於 )
用户参与
星數610
關注者數8
派生數48
提交數64
已啟用問題?
問題數22
打開的問題數7
拉請求數9
打開的拉請求數3
關閉的拉請求數1
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?