fast-levenshtein
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -9,3 +9,3 @@ { | ||
"description": "Efficient implementation of Levenshtein algorithm with asynchronous callback support", | ||
"main": "levenshtein.min.js", | ||
"main": "levenshtein.js", | ||
"moduleType": [ | ||
@@ -12,0 +12,0 @@ "amd", |
@@ -1,2 +0,2 @@ | ||
/*! fast-levenshtein 2014-07-10. Copyright Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/) */ | ||
/*! fast-levenshtein 2014-09-15. Copyright Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/) */ | ||
(function(){"use strict";var e=function(e){for(var n=Array.prototype.slice.call(arguments,1),r=0;n.length>r;++r){var t=n[r];for(var l in t)t.hasOwnProperty(l)&&(e[l]=t[l])}return e},n={get:function(e,n){if(e===n)return 0;if(0===e.length)return n.length;if(0===n.length)return e.length;var r,t,l,u,f,o=Array(n.length+1);for(l=0;o.length>l;++l)o[l]=l;for(l=0;e.length>l;++l){for(t=l+1,u=0;n.length>u;++u)r=t,t=o[u]+(e.charAt(l)===n.charAt(u)?0:1),f=r+1,t>f&&(t=f),f=o[u+1]+1,t>f&&(t=f),o[u]=r;o[u]=t}return t},getAsync:function(n,r,t,l){if(l=e({},{progress:null},l),n===r)return t(null,0);if(0===n.length)return t(null,r.length);if(0===r.length)return t(null,n.length);var u,f,o,i,a,g,h,c=Array(r.length+1);for(o=0;c.length>o;++o)c[o]=o;f=1,o=0,i=-1;var d=function(){for(g=(new Date).valueOf(),h=g;1e3>h-g;){if(r.length<=++i){if(c[i]=f,n.length<=++o)return t(null,f);f=o+1,i=0}u=f,f=c[i]+(n.charAt(o)===r.charAt(i)?0:1),a=u+1,f>a&&(f=a),a=c[i+1]+1,f>a&&(f=a),c[i]=u,h=(new Date).valueOf()}if(null!==l.progress)try{l.progress.call(null,100*o/n.length)}catch(e){return t("Progress callback: "+(""+e))}setTimeout(d(),0)};d()}};"undefined"!=typeof define&&null!==define&&define.amd?define(function(){return n}):"undefined"!=typeof module&&null!==module?module.exports=n:"undefined"!=typeof window&&null!==window&&(window.Levenshtein=n)})(); |
@@ -0,1 +1,3 @@ | ||
(MIT License) | ||
Copyright (c) 2013 [Ramesh Nair](http://www.hiddentao.com/) | ||
@@ -2,0 +4,0 @@ |
{ | ||
"name": "fast-levenshtein", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Efficient implementation of Levenshtein algorithm with asynchronous callback support", | ||
@@ -32,3 +32,3 @@ "main": "levenshtein.js", | ||
"author": "Ramesh Nair <ram@hiddentao.com> (http://www.hiddentao.com/)", | ||
"license": "BSD" | ||
"license": "MIT" | ||
} |
@@ -34,10 +34,4 @@ # fast-levenshtein - Levenshtein algorithm in Javascript | ||
Or the following inside your HTML: | ||
If you are not using any module loader system then the API will then be accessible via the `window.Levenshtein` object. | ||
```html | ||
<script type="text/javascript" src="https://github.com/hiddentao/fast-levenshtein/raw/master/levenshtein.min.js"></script> | ||
``` | ||
The API will then be accessible via the `window.Levenshtein` object. | ||
## Examples | ||
@@ -44,0 +38,0 @@ |
@@ -52,2 +52,6 @@ var _ = require('lodash'), | ||
// equal strings | ||
_.extend(tests, createTests('hello', 'hello', 0)); | ||
// inserts | ||
for (i=0; i<=str.length; ++i) { | ||
@@ -60,2 +64,3 @@ str1 = str.substr(0,i); | ||
// deletes | ||
for (i=str.length-1; i>=0; --i) { | ||
@@ -68,7 +73,18 @@ str1 = str; | ||
_.extend(tests, createTests('Hello', 'hello', 1)); | ||
_.extend(tests, createTests('book', 'back', 2)); | ||
_.extend(tests, createTests('kitten', 'sitting', 3)); | ||
_.extend(tests, createTests('kitten', 'kttn', 2)); | ||
// substitutions | ||
_.extend(tests, createTests("a", "b", 1 )); | ||
_.extend(tests, createTests("ab", "ac", 1 )); | ||
_.extend(tests, createTests("ac", "bc", 1 )); | ||
_.extend(tests, createTests("abc", "axc", 1 )); | ||
_.extend(tests, createTests("xabxcdxxefxgx", "1ab2cd34ef5g6", 6 )); | ||
// many ops | ||
_.extend(tests, createTests('xabxcdxxefxgx', 'abcdefg', 6)); | ||
_.extend(tests, createTests('javawasneat', 'scalaisgreat', 7)); | ||
_.extend(tests, createTests("example", "samples", 3)); | ||
_.extend(tests, createTests("sturgeon", "urgently", 6 )); | ||
_.extend(tests, createTests("levenshtein", "frankenstein", 6 )); | ||
_.extend(tests, createTests("distance", "difference", 5 )); | ||
// non-latin | ||
_.extend(tests, createTests('因為我是中國人所以我會說中文', '因為我是英國人所以我會說英文', 2, { | ||
@@ -78,2 +94,3 @@ description: 'non-latin' | ||
// long text | ||
_.extend(tests, createTests( | ||
@@ -84,3 +101,3 @@ 'Morbi interdum ultricies neque varius condimentum. Donec volutpat turpis interdum metus ultricies vulputate. Duis ultricies rhoncus sapien, sit amet fermentum risus imperdiet vitae. Ut et lectus', | ||
{ | ||
description: 'sentence' | ||
description: 'long text' | ||
} | ||
@@ -87,0 +104,0 @@ )); |
36095
561
121