Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
js-levenshtein
Advanced tools
The most efficient JS implementation calculating the Levenshtein distance, i.e. the difference between two strings.
The js-levenshtein npm package is used to calculate the Levenshtein distance between two strings. The Levenshtein distance is a measure of the difference between two sequences, which is 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. In the code sample, the distance between 'kitten' and 'sitting' is calculated, which is 3.
const levenshtein = require('js-levenshtein');
let distance = levenshtein('kitten', 'sitting');
console.log(distance); // Output: 3
This package provides a fast implementation of the Levenshtein algorithm. It is optimized for speed and is often faster than js-levenshtein, especially for longer strings.
This is another package that calculates the Levenshtein distance. It has a simple API and is also quite performant, but it may not be as optimized for speed as fast-levenshtein.
Natural is a general natural language facility for Node.js. It includes a Levenshtein distance function as part of its broader set of language processing tools, which makes it more versatile than js-levenshtein if you need additional natural language processing features.
A very efficient JS implementation calculating the Levenshtein distance, i.e. the difference between two strings.
Based on Wagner-Fischer dynamic programming algorithm, optimized for speed and memory
$ npm install --save js-levenshtein
const levenshtein = require('js-levenshtein');
levenshtein('kitten', 'sitting');
//=> 3
$ npm run bench
50 paragraphs, length max=500 min=240 avr=372.5
162 op/s » js-levenshtein
98 op/s » talisman
94 op/s » levenshtein-edit-distance
85 op/s » leven
39 op/s » fast-levenshtein
100 sentences, length max=170 min=6 avr=57.5
3,076 op/s » js-levenshtein
2,024 op/s » talisman
1,817 op/s » levenshtein-edit-distance
1,633 op/s » leven
800 op/s » fast-levenshtein
2000 words, length max=20 min=3 avr=9.5
3,119 op/s » js-levenshtein
2,416 op/s » talisman
2,141 op/s » levenshtein-edit-distance
1,855 op/s » leven
1,260 op/s » fast-levenshtein
Benchmarks was performed with node v8.12.0 on a MacBook Pro 15", 2.9 GHz Intel Core i9
MIT © Gustaf Andersson
FAQs
The most efficient JS implementation calculating the Levenshtein distance, i.e. the difference between two strings.
The npm package js-levenshtein receives a total of 2,921,047 weekly downloads. As such, js-levenshtein popularity was classified as popular.
We found that js-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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.