
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Measure the difference between two strings using the fastest JS implementation of the Levenshtein distance algorithm
The leven npm package is a JavaScript library for measuring the difference between two strings. It uses the Levenshtein distance algorithm to calculate the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one word into the other. This can be particularly useful in applications that need to perform fuzzy matching, spell checking, or any scenario where determining how similar two strings are is necessary.
Calculate Levenshtein distance
This feature allows you to calculate the Levenshtein distance between two strings, which is the number of edits needed to transform one string into the other. The code sample demonstrates how to use the leven package to find the distance between 'kitten' and 'sitting', which is 3.
"const leven = require('leven');\nconsole.log(leven('kitten', 'sitting')); // 3"
This package provides a fast implementation of the Levenshtein distance algorithm. It is optimized for performance and can be faster than leven in some cases. However, leven is known for its simplicity and ease of use, making it a preferred choice for straightforward applications.
Fuzzyset.js is a more comprehensive library for fuzzy string matching. It not only calculates the Levenshtein distance but also provides additional functionality for finding close matches within a set of strings. Compared to leven, it offers a broader set of features for applications that require more than just distance calculation.
This package compares two strings and returns a score based on their similarity. It includes a method to find the best match in an array of strings. While leven focuses solely on calculating the Levenshtein distance, string-similarity provides a more nuanced approach to comparing string similarity, making it suitable for applications that need to rank multiple potential matches.
Measure the difference between two strings
The fastest JS implementation of the Levenshtein distance algorithm
$ npm install --save leven
const leven = require('leven');
leven('cat', 'cow');
//=> 2
$ npm run bench
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
MIT © Sindre Sorhus
FAQs
Measure the difference between two strings using the Levenshtein distance algorithm
The npm package leven receives a total of 27,471,334 weekly downloads. As such, leven popularity was classified as popular.
We found that leven 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
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.