New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nearest-string

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nearest-string

Find the nearest string with a given string

  • 1.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

nearest-string

NPM version

Find the nearest string with a given string (used Levenstein distance for compare string).

Install

npm install --save nearest-string

Usage

Basic usage:

var nearestString = require('nearest-string');

var strings = [
    'foo',
    'bar',
    'baz'
];

var nearestStringKey = nearestString(strings, 'fooo').key;      // expected: 0
var nearestStringValue = nearestString(strings, 'fooo').value;  // expected: foo
var nearestStringDistance = nearestString(strings, 'fooo').distance;  // expected: 1 - Levenstein distance
var nearestStringDistances = nearestString(strings, 'fooo').distances;  // expected: [ 1, 4, 4 ] - array of Levenstein distances

If you want to find nearest string case insensitive use third argument as true (it's false by default):

nearestString(strings, 'fooo', false).distance;  // expected: 1 - Levenstein distance case sensitive
nearestString(strings, 'Fooo', false).distance;  // expected: 2 - Levenstein distance case sensitive
nearestString(strings, 'fooo', true).distance;   // expected: 1 - Levenstein distance case insensitive
nearestString(strings, 'Fooo', true).distance;   // expected: 1 - Levenstein distance case insensitive

Test

npm test

Keywords

FAQs

Package last updated on 11 Apr 2018

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