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.
damerau-levenshtein
Advanced tools
Damerau - Levenshtein distance by The Spanish Inquisition + relative distance
The damerau-levenshtein npm package is used to calculate the Damerau-Levenshtein distance between two strings. This distance is a measure of similarity between two strings, considering the number of operations (insertions, deletions, substitutions, and transpositions) needed to transform one string into another. It is particularly useful in applications like spell checking, typo correction, and other forms of text analysis where slight variations in string input need to be quantified.
Calculate Distance and Steps
This feature allows users to calculate the Damerau-Levenshtein distance between two strings and also provides detailed steps of the operations needed to transform the source string into the target string. This is useful for understanding the specific changes needed.
const damerau = require('damerau-levenshtein');
const result = damerau('hello', 'hallo');
console.log(result.distance); // Output: 2
console.log(result.steps); // Output: [ { operation: 'substitute', srcPos: 1, destPos: 1 }, { operation: 'substitute', srcPos: 4, destPos: 4 } ]
This package provides an efficient way to compute the Levenshtein distance. Unlike damerau-levenshtein, it does not account for transpositions, making it slightly less versatile for certain applications but faster for simple distance calculations.
Similar to fast-levenshtein, this package calculates the Levenshtein distance between two strings. It is optimized for performance but, like fast-levenshtein, does not handle transpositions, which can be crucial for more detailed text analysis compared to damerau-levenshtein.
It provides a function that takes two string arguments and returns a hash like this:
{
steps: 5, // Levenstein demerau distance
relative: 0.7, // steps / length of the longer string
similarity: 0.3 // 1 - relative
}
npm install damerau-levenshtein
import * as levenshtein from 'damerau-levenshtein';
const lev = levenshtein('hello world', 'Hello World!');
// { steps: 4, relative: 0.3076923076923077, similarity: 0.6923076923076923 }
Please see tests for more insights.
import * as levenshtein from 'damerau-levenshtein';
interface LevenshteinResponse {
steps: number;
relative: number;
similarity: number;
}
const lev: LevenshteinResponse = levenshtein('hello world', 'Hello World!');
console.log(lev.steps);
// 2
console.log(lev.foo);
// TypeScript Error: Property 'foo' does not exist on type 'LevenshteinResponse'.
[1.0.8] - 2021-12-20
Security:
FAQs
Damerau - Levenshtein distance by The Spanish Inquisition + relative distance
The npm package damerau-levenshtein receives a total of 13,269,362 weekly downloads. As such, damerau-levenshtein popularity was classified as popular.
We found that damerau-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.