1.1.0 • Published 5 years ago

levenshteiner v1.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

Levenshteiner

Version Build Status Bundle Size Required Node License

TL;DR

This is one of the fastest packages to calculate Levenshtein distance available today for the Node.js. It utilizes features of worker_threads module which is released with Node.js 12+. It becomes LTS version of Node on October 2019, so you should be able to use this package in production right now.

Installation

Just run npm install --save levenshteiner or yarn add levenshteiner and you should be ready to go. To use the package in your app, import is as

import levenshteiner form 'levenshteiner'

or

const levenshteiner = require('levenshteiner');

Usage

This package provides three main methods:

  • levenshtein(strA: string, strB: string): number which calculates Levenshtein distance between two strings.
  • levenshteinOnArray(givenString: string, dictionary: string[]): { value: string, distance: number} | null which finds the item in dictionary with the lowest distance to givenString
  • levenshteinOnArrayAsync(givenString: string, dictionary: string[]): Promise<{value: string, distance: number} | null> which also finds the closest to the givenString value from the dictionary array. However, this method utilizes worker_threads to parallelize calculations, so performance is significantly better with new threds capability of Node.js

Two last methods will return null in case if dictionary is not an Array of non-zero length all elements of which are strings.

import { levenshtein, levenshteinOnArray, levenshteinOnArrayAsync } from 'levenshteiner';

const possibleValues = [
  'Apple',
  'Banana',
  'Pineaple',
  'Watermelon',
];

const inputString = 'Bnana';

const distanceInputToApple = levenshtein(inputString, possibleValues[0]); // distanceInputToApple = 3
const possibleMatch = levenshteinOnArray(inputStringm, possibleValues); // { value: 'Banana', distance: 1 }

License

This package is released under the MIT License.

1.1.0

5 years ago

1.0.0

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago