Files
NapCatQQ/.pnpm-store/v3/files/60/7e86f97880250b4aed0eedcabe0613eae589291ffb1106f2785ef2e7c78ba92e08613779c845ee3728491a5b311b614ec6166e7ccc26ad48542fe5c932204c
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

48 lines
1.1 KiB
Plaintext

[![NPM](https://nodei.co/npm/damerau-levenshtein.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/damerau-levenshtein/)
It provides a function that takes two string arguments and returns a hash like this:
``` javascript
{
steps: 5, // Levenstein demerau distance
relative: 0.7, // steps / length of the longer string
similarity: 0.3 // 1 - relative
}
```
## Install
```sh
npm install damerau-levenshtein
```
## Use with ES6 modules
```js
import * as levenshtein from 'damerau-levenshtein';
const lev = levenshtein('hello world', 'Hello World!');
// { steps: 4, relative: 0.3076923076923077, similarity: 0.6923076923076923 }
```
Please see [tests](./test/test.js) for more insights.
## Use with TypeScript
```ts
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'.
```