How Similar
This module compares two strings and returns a value on how similar they are from 0 - 1 (using a normalized levenshtein distance). The most basic use is:
> const similarity = > 0833
The module can also compare a string to an array of strings to find which one is the most similar one:
> key: 'Dublin' value: 1 key: 'Doblin' value: 0875 key: 'Devlin' value: 075 key: 'Duuublin' value: 075
Install
You can install with [npm]:
$ npm install --save how-similar
Usage
The module provides functions to deal with string / string comparison and string / array comparison. Still the easiest way to use it is to import similarity
:
> const similarity =
Then as shown above you can pass two strings or an string and an array of strings. You can also pass a third parameter with options (it will be explained next).
Examples
The following use cases can be solved with the module:
- How similar are two different strings:
> 0833
- What is the most similar string in an array to another string:
> key: 'Dublin' value: 1 key: 'Doblin' value: 0875 ...
- How similar ignoring the case (
{ignorecase: true}
):
> 1
- How similar stemming the words (
{stem: true}
):
> 1
- How similar with exceptions (
{except: [word1, word2, ...]}
)
> 1
License
Copyright © 2019, Juan Convers. Released under the MIT License.