New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

how-close

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

how-close

Compare the similarity between two strings with JavaScript.

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
0
Created
Source

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

Keywords

string similarity

FAQs

Package last updated on 18 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts