Home

Awesome

similarity

Build Coverage Downloads Size

How similar are these two strings?

Install

npm:

npm install similarity

Use

var similarity = require('similarity')

similarity('food', 'food') // 1
similarity('food', 'fool') // 0.75
similarity('ding', 'plow') // 0
similarity('chicken', 'chick') // 0.714285714
similarity('ES6-Shim', 'es6 shim') // 0.875 (case insensitive)
similarity('ES6-Shim', 'es6 shim', {sensitive: true}) // 0.5 (case sensitive)

API

similarity(left, right[, options])

Get the similarity (number) between two values (strings), where 0 is dissimilar, and 1 is equal.

CLI

Usage: similarity [options] <word> <word>

How similar are these two strings?

Options:

  -h, --help           output usage information
  -v, --version        output version number
  -s, --sensitive      be sensitive to casing differences

Usage:

# output similarity
$ similarity sitting kitten
0.5714285714285714
$ similarity saturday sunday
0.625

See also

Note: This module uses Levenshtein distance to measure similarity, but there are many other algorithms for string comparison. Here are a few:

License

ISC © Zeke Sikelianos

<!-- Definitions -->