# closest-match

> Uses Levenshtein Distance to find the closest string match or matches in an array

Latest version **1.3.3** (published 2021-09-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install closest-match
pnpm add closest-match
yarn add closest-match
bun add closest-match
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.3 |
| Published | 2021-09-01 |
| First published | 2021-08-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Plebus Supremus |
| Maintainers | plebus_supremus |
| Keywords | levenshtien, leven, closest-match |

## Links

- npm: https://www.npmjs.com/package/closest-match
- npm.io page: https://npm.io/package/closest-match

## Recent versions

- 1.3.3 (latest) — 2021-09-01
- 1.3.0 — 2021-08-31

## README

# Closest Match
An NPM module that finds the closest string match or matches in an array using [Levenshtein Distance](https://en.wikipedia.org/wiki/Levenshtein_distance)

# Installation

```
npm i closest-match
```

# Usage

```js
const closest_match = require("closest-match");

closest_match.distance(text1, text2) // Difference between text1 and text2
// (Number of changes need to get from text1 to text2)

closest_match.closestMatch(text, array) // Closest match of text in an array

closest_match.closestMatch(text, array, true) // An array of all elements in an array that are closest to the text
```

# Methods

| Method | Explanation |
|-|-|
| distance(text1, text2) | Returns the Levenshtein difference between the strings. |
| closestMatch(text, array, showOccurrences) | Returns the closest match of a specified string in an array. If showOccurrences is true, then it returns an array of all of  the closest matches to the string in an array. |

# Examples

```js
const { distance, closestMatch } = require("closest-match");

console.log(distance("hlelo", "hello")); // 2

console.log(closestMatch("dag", ["dog", "pumpkin"])); //dog

console.log(closestMatch("hello", ["jello", "yellow", "bello"], true)); // ["jello", "bello"]
```

---
_Source: https://npm.io/package/closest-match · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
