gestalt-pattern-matcher
![downloads](https://camo.githubusercontent.com/a3f40aa6dda237668e6485968d134cf1e0e97b08136240778d5161d8d2bb9ff9/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f64742f67657374616c742d7061747465726e2d6d6174636865723f7374796c653d666c61742d737175617265)
This is an implementation of the Ratcliff/Obershelp Gestalt pattern-matching algorithm in NodeJS.
Its purpose is to compare two strings and determine approximately how different they are: a score of 0 indicates that they share no characters at all, while a score of 1 indicates that the two strings are identical.
This implementation is suitable for short strings (on the order of 1000 characters long). I haven't thoroughly analyzed complexity, but it is roughly O(n^2)
average case, O(n^3)
in the worst case, and O(n)
in the best case.
Install
Just install it with npm
or yarn
.
npm install gestalt-pattern-matcher
# or
yarn add gestalt-pattern-matcher
Usage
// ES7
import gestaltSimilarity from "gestalt-pattern-matcher";
const firstString = "Test 1";
const secondString = "Test 2";
console.log(gestaltSimilarity(firstString, secondString));
// commonJS
const gestaltSimilarity = require("gestalt-pattern-matcher").default;
const firstString = "Test 1";
const secondString = "Test 2";
console.log(gestaltSimilarity(firstString, secondString));
Notice
This npm module is based on GitSage gestalt-pattern-matcher repository, whom we personally thank the author for the contributions.