npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

string-metric

v0.3.3

Published

Get string similarity in JavaScript or TypeScript

Downloads

811

Readme

String Metric

Build Status Coverage Status npm npm

A library implementing different string similarity and distance measures, and Implement by TypeScript. Also, you can use in JavaScript.

Algorithm reference java-string-similarity

Install

npm install string-metric

Progress

| Algorithm | Complete? | | ------------------------------------------------- | --------- | | Jaro-Winkler | Yes | | Levenshtein | Yes | | Normalized-Levenshtein | Yes | | Weighted-Levenshtein | Yes | | Damerau | Yes | | Optimal-String-Alignment |Yes| | Longest-Common-Subsequence | Yes | | Metric-Longest-Common-Subsequence | Yes | | N-Gram | Yes | | Q-Gram | No | | Shingle (n-gram) based algorithms | No | | Cosine similarity | No | | Jaccard index | No | | Sorensen-Dice coefficient | No | | Ratcliff-Obershelp | No |

Jaro-Winkler

For more specs, please go to tests/JaroWinkler.spec.ts in the repository.

const instance = new JaroWinkler();

const s1 = 'My string';
const s2 = 'My string';
instance.similarity(s1, s2); // 1

const s1 = 'My string';
const s2 = 'My tsring';
instance.similarity(s1, s2); // 0.974074

const s1 = 'My string';
const s2 = 'My ntrisg';
instance.similarity(s1, s2); // 0.896296

Levenshtein

For more specs, please go to tests/Levenshtein.spec.ts in the repository.

const instance = new Levenshtein();

const s1 = 'My string';
const s2 = 'My string';
instance.distance(s1, s2); // 0

const s1 = 'My string';
const s2 = 'My tring';
instance.distance(s1, s2); // 1

const s1 = 'My string';
const s2 = 'M string2';
instance.distance(s1, s2); // 2

Normalized-Levenshtein

For more specs, please go to tests/NormalizedLevenshtein.spec.ts in the repository.

const instance = new NormalizedLevenshtein();

Weighted-Levenshtein

For more specs, please go to tests/WeightedLevenshtein.spec.ts in the repository.

const instance = new WeightedLevenshtein();

Damerau

For more specs, please go to tests/Damerau.spec.ts in the repository.

const instance = new Damerau();

const s1 = 'ABCDEF';
const s2 = 'ABDCEF';
instance.distance(s1, s2); // 1

const s1 = 'ABCDEF';
const s2 = 'BACDFE';
instance.distance(s1, s2); // 2

const s1 = 'ABCDEF';
const s2 = 'ABCDE';
instance.distance(s1, s2); // 1

Optimal-String-Alignment

For more specs, please go to tests/OptimalStringAlignment.spec.ts in the repository.

const instance = new OptimalStringAlignment();

const s1 = 'ABDCEF';
const s2 = 'ADCEF';
instance.distance(s1, s2); // 1

const s1 = 'BAC';
const s2 = 'CAB';
instance.distance(s1, s2); // 2

const s1 = 'CA';
const s2 = 'ABC';
instance.distance(s1, s2); // 3

Longest-Common-Subsequence

For more specs, please go to tests/LongestCommonSubsequence.spec.ts in the repository.

const instance = new LongestCommonSubsequence();

const s1 = 'AGCAT';
const s2 = 'GAC';
instance.distance(s1, s2); // 4

const s1 = 'AGCAT';
const s2 = 'AGCT';
instance.distance(s1, s2); // 1

Metric-Longest-Common-Subsequence

For more specs, please go to tests/MetricLCS.spec.ts in the repository.

const instance = new MetricLCS();

N-Gram

For more specs, please go to tests/NGram.spec.ts in the repository.

const instance = new NGram();

const s1 = 'SIJK';
const s2 = 'SIJK';
instance.distance(s1, s2); // 0

const s0 = 'ABABABAB';
const s1 = 'ABCABCABCABC';
const s2 = 'POIULKJH';
instance.distance(s0, s1) < instance.distance(s0, s2); // true