nearest-string
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 = ; var strings = 'foo' 'bar' 'baz'; var nearestStringKey = key; // expected: 0var nearestStringValue = value; // expected: foovar nearestStringDistance = distance; // expected: 1 - Levenstein distancevar nearestStringDistances = 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):
distance; // expected: 1 - Levenstein distance case sensitivedistance; // expected: 2 - Levenstein distance case sensitivedistance; // expected: 1 - Levenstein distance case insensitivedistance; // expected: 1 - Levenstein distance case insensitive
Test
npm test