Socket
Socket
Sign inDemoInstall

damerau-levenshtein

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    damerau-levenshtein

Damerau - Levenshtein distance by The Spanish Inquisition + relative distance


Version published
Weekly downloads
13M
decreased by-0.44%
Maintainers
1
Install size
12.6 kB
Created
Weekly downloads
 

Package description

What is damerau-levenshtein?

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.

What are damerau-levenshtein's main functionalities?

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 } ]

Other packages similar to damerau-levenshtein

Changelog

Source

[1.0.8] - 2021-12-20

Security:

  • Upgrade mocha to > 9.0.0 (fixes three security vulnerabilities brought by transitive dependencies)

Readme

Source

NPM

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
}

Install

npm install damerau-levenshtein

Use with ES6 modules

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.

Use with TypeScript

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'.

Keywords

FAQs

Last updated on 06 Jan 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc