JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 56817
  • Score
    100M100P100Q154620F
  • License MIT

Calculates similarity between two strings

Package Exports

  • string-similarity-js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (string-similarity-js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Build Status codecov Wallaby.js

String Similarity

A simple, lightweight string similarity function based on comparing the number of substrings (typically bigrams) in common between any two strings. Returns a score between 0 and 1 indicating the strength of the match.

Loosely based on the Sørensen–Dice coefficient, this algorithm is most effective at detecting rearranged words or misspellings. It tends to be less effective with very short strings unless you pass in substringLength of 1 (returning number of letters in common).

It is case insensitive unless you specify case sensitivity. Does not ignore punctuation or spaces. In some cases, removing punctuation beforehand may improve matching accuracy.

Usage

import {getStringSimilarity} from "string-similarity";

// Rearranged words
getStringSimilarity("Lorem ipsum", "Ipsum lorem")
// Returns a score of 0.9

// Typos
getStringSimilarity("The quick brown fox jumps over the lazy dog", "The quck brown fx jumps over the lazy dog")
// 0.92

// Even more different
getStringSimilarity("The quick brown fox jumps over the lazy dog", "The quack brain fax jomps odor the lady frog")
// 0.65

// Completely different strings
getStringSimilarity("The quick brown fox jumps over the lazy dog", "Lorem ipsum")
// 0.07

// Tiny strings are less effective with default settings
getStringSimilarity("DMV", "DNV")
// Returns 0, because technically there are no bigrams in common between the two

// Passing in a substring length of 1 may improve accuracy on tiny strings
getStringSimilarity("DMV", "DNV", 1)
// Returns 0.67, the percentage of letters in common between the two

License

This project is licensed under the MIT License - see the LICENSE.md file for details