Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
fast-levenshtein
Advanced tools
Efficient implementation of Levenshtein algorithm with asynchronous callback support
The fast-levenshtein npm package is a high-performance JavaScript implementation of the Levenshtein algorithm, which measures the difference between two sequences. It is commonly used to determine the similarity between two strings by calculating the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one word into the other.
Calculate Levenshtein distance
This feature allows you to calculate the Levenshtein distance between two strings. The code sample demonstrates how to use the package to find the distance between 'back' and 'book', which is 2.
const levenshtein = require('fast-levenshtein');
const distance = levenshtein.get('back', 'book');
console.log(distance); // Output: 2
This package provides a simple implementation of the Levenshtein algorithm. It is not as performance-optimized as fast-levenshtein but is straightforward to use for basic needs.
Similar to fast-levenshtein, this package calculates the Levenshtein edit distance. It focuses on being a small and fast implementation, but fast-levenshtein might still have performance advantages in certain scenarios.
This package goes beyond just calculating the Levenshtein distance by providing a way to compare two strings and find the similarity percentage. It uses a different algorithm for comparison and can be used for more complex string comparison tasks.
Natural is a general natural language facility for Node.js. It includes a Levenshtein distance implementation among other features like tokenization, stemming, classification, phonetics, and more. It is more comprehensive but less specialized than fast-levenshtein.
An efficient Javascript implementation of the Levenshtein algorithm with asynchronous callback support.
Install using npm:
$ npm install fast-levenshtein
Using bower:
$ bower install fast-levenshtein
Or the following inside your 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.
Synchronous
var levenshtein = require('fast-levenshtein');
var distance = levenshtein.get('back', 'book'); // 2
var distance = levenshtein.get('我愛你', '我叫你'); // 1
Asynchronous
var levenshtein = require('fast-levenshtein');
levenshtein.getAsync('back', 'book', function (err, distance) {
// err is null unless an error was thrown
// distance equals 2
});
Asynchronous with progress updates
var levenshtein = require('fast-levenshtein');
var hugeText1 = fs.readFileSync(...);
var hugeText2 = fs.readFileSync(...);
levenshtein.getAsync(hugeText1, hugeText2, function (err, distance) {
// process the results as normal
}, {
progress: function(percentComplete) {
console.log(percentComplete + ' % completed so far...');
}
);
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]...
>> fast-levenshtein x 357 ops/sec ±2.32% (89 runs sampled)
>> levenshtein-edit-distance x 317 ops/sec ±4.16% (83 runs sampled)
>> natural x 219 ops/sec ±5.26% (77 runs sampled)
>> levenshtein x 179 ops/sec ±2.49% (73 runs sampled)
Benchmark done.
Fastest test is fast-levenshtein at 1.13x faster than levenshtein-edit-distance
You can run this benchmark yourself using:
$ npm install -g grunt-cli
$ npm install
$ 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
FAQs
Efficient implementation of Levenshtein algorithm with locale-specific collator support.
The npm package fast-levenshtein receives a total of 30,271,713 weekly downloads. As such, fast-levenshtein popularity was classified as popular.
We found that fast-levenshtein demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.