Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

leven

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

leven - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

44

index.js

@@ -11,2 +11,11 @@ /* eslint-disable no-nested-ternary */

var swap = a;
// Swapping the strings if `a` is longer than `b` so we know which one is the
// shortest & which one is the longest
if (a.length > b.length) {
a = b;
b = swap;
}
var aLen = a.length;

@@ -23,2 +32,31 @@ var bLen = b.length;

// Performing suffix trimming:
// We can linearly drop suffix common to both strings since they
// don't increase distance at all
// Note: `~-` is the bitwise way to perform a `- 1` operation
while (aLen > 0 && (a.charCodeAt(~-aLen) === b.charCodeAt(~-bLen))) {
aLen--;
bLen--;
}
if (aLen === 0) {
return bLen;
}
// Performing prefix trimming
// We can linearly drop prefix common to both strings since they
// don't increase distance at all
var start = 0;
while (start < aLen && (a.charCodeAt(start) === b.charCodeAt(start))) {
start++;
}
aLen -= start;
bLen -= start;
if (aLen === 0) {
return bLen;
}
var bCharCode;

@@ -32,3 +70,3 @@ var ret;

while (i < aLen) {
charCodeCache[i] = a.charCodeAt(i);
charCodeCache[start + i] = a.charCodeAt(start + i);
arr[i] = ++i;

@@ -38,3 +76,3 @@ }

while (j < bLen) {
bCharCode = b.charCodeAt(j);
bCharCode = b.charCodeAt(start + j);
tmp = j++;

@@ -44,3 +82,3 @@ ret = j;

for (i = 0; i < aLen; i++) {
tmp2 = bCharCode === charCodeCache[i] ? tmp : tmp + 1;
tmp2 = bCharCode === charCodeCache[start + i] ? tmp : tmp + 1;
tmp = arr[i];

@@ -47,0 +85,0 @@ ret = arr[i] = tmp > ret ? tmp2 > ret ? ret + 1 : tmp2 : tmp2 > tmp ? tmp + 1 : tmp2;

15

package.json
{
"name": "leven",
"version": "2.0.0",
"version": "2.1.0",
"description": "Measure the difference between two strings using the fastest JS implementation of the Levenshtein distance algorithm",

@@ -43,4 +43,4 @@ "license": "MIT",

"devDependencies": {
"ava": "*",
"fast-levenshtein": "^1.0.3",
"ava": "^0.17.0",
"fast-levenshtein": "^2.0.5",
"ld": "^0.1.0",

@@ -50,7 +50,8 @@ "levdist": "^2.0.0",

"levenshtein-component": "0.0.1",
"levenshtein-edit-distance": "^1.0.0",
"matcha": "^0.6.0",
"natural": "^0.2.1",
"xo": "*"
"levenshtein-edit-distance": "^2.0.0",
"matcha": "^0.7.0",
"natural": "^0.4.0",
"talisman": "^0.18.0",
"xo": "^0.16.0"
}
}
# leven [![Build Status](https://travis-ci.org/sindresorhus/leven.svg?branch=master)](https://travis-ci.org/sindresorhus/leven)
> Measure the difference between two strings
> Measure the difference between two strings<br>
> The fastest JS implementation of the [Levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance) algorithm

@@ -17,3 +17,3 @@

```js
var leven = require('leven');
const leven = require('leven');

@@ -32,10 +32,11 @@ leven('cat', 'cow');

```
343,757 op/s » leven
264,625 op/s » levenshtein-edit-distance
49,981 op/s » fast-levenshtein
25,496 op/s » levenshtein-component
18,240 op/s » levdist
17,554 op/s » ld
12,633 op/s » natural
9,960 op/s » levenshtein
401,487 op/s » leven
371,707 op/s » talisman
264,191 op/s » levenshtein-edit-distance
152,923 op/s » fast-levenshtein
57,267 op/s » levenshtein-component
19,915 op/s » levdist
21,802 op/s » ld
18,079 op/s » natural
11,761 op/s » levenshtein
```

@@ -51,2 +52,2 @@

MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc