leven
- Version 4.1.0
- Published
- 10.2 kB
- No dependencies
- MIT license
Install
npm i leven
yarn add leven
pnpm add leven
Overview
Measure the difference between two strings using the Levenshtein distance algorithm
Index
Functions
Interfaces
Functions
function closestMatch
closestMatch: ( target: string, candidates: readonly string[], options?: Options) => string | undefined;
Find the closest matching string from an array of candidates.
Parameter target
The string to find matches for.
Parameter candidates
Array of candidate strings to search through.
Parameter options
Options.
Returns
The closest matching string from candidates, or
undefined
if no candidates are provided or if no match is found withinmaxDistance
.Example 1
import {closestMatch} from 'leven';closestMatch('kitten', ['sitting', 'kitchen', 'mittens']);//=> 'kitchen'closestMatch('hello', ['jello', 'yellow', 'bellow'], {maxDistance: 2});//=> 'jello'
function leven
leven: (first: string, second: string, options?: Options) => number;
Measure the difference between two strings using the Levenshtein distance algorithm.
Parameter first
First string.
Parameter second
Second string.
Parameter options
Options.
Returns
Distance between
first
andsecond
. IfmaxDistance
is provided and the actual distance exceeds it, returnsmaxDistance
.Example 1
import leven from 'leven';leven('cat', 'cow');//=> 2
Interfaces
interface Options
interface Options {}
property maxDistance
readonly maxDistance?: number;
Maximum Levenshtein distance to calculate.
If the actual distance exceeds this value, the function will return the maximum distance instead of the actual distance. This can significantly improve performance when you only care about matches within a certain threshold.
Example 1
``` import leven from 'leven';
leven('abcdef', '123456', {maxDistance: 3}); //=> 3
leven('cat', 'cow', {maxDistance: 5}); //=> 2 ```
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (11)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/leven
.
- Markdown[](https://www.jsdocs.io/package/leven)
- HTML<a href="https://www.jsdocs.io/package/leven"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3621 ms. - Missing or incorrect documentation? Open an issue for this package.