Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

how-close

jrmedd8WTFPL1.1.1TypeScript support: included

Compare the similarity between two strings with JavaScript.

string similarity, string comparison, edit distance, levenshtein distance, text similarity, fuzzy matching, string matching, text comparison, string analysis

readme

build

HowClose

A JavaScript module to compare the similarity between two strings. It returns a value between 0 and 1 indicating how similar the shorter string is to the larger string.

Installation

Install via npm:

npm install how-close

Usage

const HowClose = require("how-close");

const comparison = new HowClose("kitten", "sitting");
console.log(comparison.percentage); // Similarity score
console.log(comparison.contains); // Whether the first string contains the second string

API

HowClose(s1, s2) Creates a new instance of the HowClose class.

  • s1: First string.
  • s2: Second string.

Properties

  • percentage: A value between 0 and 1 indicating the similarity between the two strings.
  • contains: A boolean indicating whether the first string contains the second string. Example
  • similarity(s1, s2): A function to reinitialise the object with a new percentage.
const HowClose = require("how-close");

const comparison1 = new HowClose("hello world", "hello");
console.log(comparison1.percentage); // 0.5
console.log(comparison1.contains); // true

const comparison2 = new HowClose("large string example", "large");
console.log(comparison2.percentage); // 0.25
console.log(comparison2.contains); // true

const comparison3 = new HowClose("large", "large string example");
console.log(comparison3.percentage); // 0.25
console.log(comparison3.contains); // false