Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

closest-match

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

closest-match

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

  • 1.3.3
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
5.1K
increased by23.69%
Maintainers
1
Weekly downloads
 
Created
Source

Closest Match

An NPM module that finds the closest string match or matches in an array using Levenshtein Distance

Installation

npm i closest-match

Usage

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

MethodExplanation
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

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

Keywords

FAQs

Package last updated on 01 Sep 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc