New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

string-comparison

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-comparison

A library implementing different string similarity

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
36K
increased by3.76%
Maintainers
1
Weekly downloads
 
Created
Source

string-comparison

JavaScript implementation of tdebatty/java-string-similarity

A library implementing different string similarity, distance and sortMatch measures. A dozen of algorithms (including Levenshtein edit distance and sibblings, Jaro-Winkler, Longest Common Subsequence, cosine similarity etc.) are currently implemented. Check the summary table below for the complete list...

Download & Usage

download

npm install string-comparision --save
yarn add string-comparision

usage

let stringComparision = require('string-comparision')

const Thanos = 'healed'
const Rival = 'sealed'
const Avengers = ['edward', 'sealed', 'theatre']

use by Consine
let cos = stringComparision.consine

console.log(cos.similarity(Thanos, Rival))
console.log(cos.distance(Thanos, Rival))
console.log(cos.sortMatch(Thanos, Avengers))

OverViews

The main characteristics of each implemented algorithm are presented below. The "cost" column gives an estimation of the computational cost to compute the similarity between two strings of length m and n respectively.

Measure(s)Normalized?Metric?TypeCostTypical usage
Jaccard indexsimilarity
distance
sortMatch
YesYesSetO(m+n)
Cosine similaritysimilarity
distance
sortMatch
YesNoProfileO(m+n)
Sorensen-Dice coefficientsimilarity
distance
sortMatch
YesNoSetO(m+n)
Levenshteinsimilarity
distance
sortMatch
NoYesO(m*n)
Jaro-Winklersimilarity distance
sortMatch
YesNoO(m*n)typo correction

API

  • similarity.
  • distance.
  • sortMatch

similarity

Implementing algorithms define a similarity between strings

Params
  1. thanos [String]
  2. rival [String]
Return

Return a similarity between 0.0 and 1.0

distance

Implementing algorithms define a distance between strings (0 means strings are identical)

Params
  1. thanos [String]
  2. rival [String]
Return

Return a number

sortMatch

介绍

Params
  1. thanos [String]
  2. avengers [...String]
Return

Return an array of objects. ex:

[
  { member: 'edward', rating: 0.16666666666666663 },
  { member: 'theatre', rating: 0.4285714285714286 },
  { member: 'mailed', rating: 0.5 },
  { member: 'sealed', rating: 0.8333333333333334 }
]

Release Notes

1.0 version

  • Basic building
  • Cosine
  • DiceCoefficient
  • JaccardIndex
  • Levenshtein
  • LongestCommonSubsequence
  • MetricLCS

2.0 version

  • none

MIT

MIT

Keywords

FAQs

Package last updated on 17 Oct 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc