Socket
Socket
Sign inDemoInstall

how-similar

Package Overview
Dependencies
5
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    how-similar

Module to compare similarity between strings / arrays.


Version published
Weekly downloads
0
Maintainers
1
Install size
107 kB
Created
Weekly downloads
 

Readme

Source

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} = require('how-similar')
> similarity('Dublin', 'Doblin')
0.833

The module can also compare a string to an array of strings to find which one is the most similar one:

> similarity('Dublin', ['Doblin', 'Devlin', 'Duuublin', 'Dublin'])
[ { key: 'Dublin', value: 1 },
  { key: 'Doblin', value: 0.875 },
  { key: 'Devlin', value: 0.75 },
  { key: 'Duuublin', value: 0.75 } ]

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} = require('how-similar')

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:

  1. How similar are two different strings:
> similarity('Dublin', 'Doblin')
0.833
  1. What is the most similar string in an array to another string:
> similarity('Dublin', ['Doblin', 'Devlin', 'Duuublin', 'Dublin'])
[ { key: 'Dublin', value: 1 },
  { key: 'Doblin', value: 0.875 },
...
  1. How similar ignoring the case ({ignorecase: true}):
> similarity('Dublin', 'dUblIn', {ignorecase: true})
1
  1. How similar stemming the words ({stem: true}):
> similarity('This is Dublin', 'Thi is Dublin', {stem: true})
1
  1. How similar with exceptions ({except: [word1, word2, ...]})
> similarity('This is Dublin in Ireland', 'This is Dublin', {except: ['in', 'Ireland']})
1

License

Copyright © 2019, Juan Convers. Released under the MIT License.

Keywords

FAQs

Last updated on 16 Jan 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc