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.
Just install it with npm
or yarn
.
npm install gestalt-pattern-matcher
# or
yarn add gestalt-pattern-matcher
// 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));
This npm module is based on GitSage gestalt-pattern-matcher repository, whom we personally thank the author for the contributions.