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 🙏

© 2026 – Pkg Stats / Ryan Hefner

text-similarity-kit

v0.1.1

Published

Compare and rank short strings with TypeScript-first similarity helpers.

Downloads

236

Readme

text-similarity-kit

npm version License: MPL-2.0 CI

Compare and rank short strings with a small TypeScript-first toolkit.

text-similarity-kit is a clean-room alternative for everyday fuzzy matching tasks: search suggestions, typo-tolerant labels, command palettes, duplicate detection and lightweight record matching. It ships as ESM, has no runtime dependencies and works in Node.js or modern browsers.

Links: Demo · npm · GitHub

Package quality

  • TypeScript types are generated from the source.
  • ESM-only package with no runtime dependencies.
  • Marked as side-effect free for bundlers.
  • Tested on Node.js 20 and 22 with GitHub Actions.
  • Works in Node.js, browsers, Vite apps and static docs tooling.

Install

npm install text-similarity-kit

Quick start

import { compareStrings, findBestMatch, isSimilar, rankMatches } from "text-similarity-kit";

compareStrings("invoice export", "invoices exports");
// 0.896...

isSimilar("invoice export", "export invoices", { threshold: 0.7 });
// true

const commands = ["Create invoice", "Export invoices", "Import contacts"];

findBestMatch("export invoice", commands);
// {
//   query: "export invoice",
//   bestMatch: { candidate: "Export invoices", rating: 0.785..., index: 1 },
//   matches: [...]
// }

rankMatches("import", commands, { threshold: 0.3, limit: 2 });

API

compareStrings(left, right, options?)

Returns a score from 0 to 1, where 1 means the normalized strings are identical.

import { compareStrings } from "text-similarity-kit";

compareStrings("martha", "marhta", { algorithm: "jaro-winkler" });

Available algorithms:

| Algorithm | Good for | | --- | --- | | dice | Default. Short labels, fuzzy search, quick ranking. | | levenshtein | Typo distance and predictable edit-based scoring. | | jaro | Short names or identifiers with transposed characters. | | jaro-winkler | Name-like strings where common prefixes matter. |

jaro-winkler also accepts prefixScale and maxPrefixLength:

compareStrings("martha", "marhta", {
  algorithm: "jaro-winkler",
  prefixScale: 0.12,
  maxPrefixLength: 4
});

isSimilar(left, right, options?)

Returns a boolean by comparing two strings against a threshold.

import { isSimilar } from "text-similarity-kit";

isSimilar("invoice export", "export invoices", {
  algorithm: "jaro-winkler",
  threshold: 0.7
});
// true

threshold defaults to 0.8 and is clamped between 0 and 1.

rankMatches(query, candidates, options?)

Ranks candidates from best to worst. Ties keep the original candidate order.

import { rankMatches } from "text-similarity-kit";

const matches = rankMatches("pay export", ["payment export", "search endpoint"], {
  threshold: 0.25,
  limit: 5
});

threshold keeps only matches with a rating at or above that score. limit caps the number of returned matches after sorting.

Each match has:

type MatchResult = {
  candidate: string;
  rating: number;
  index: number;
};

findBestMatch(query, candidates, options?)

Returns the best candidate plus the full ranked list.

import { findBestMatch } from "text-similarity-kit";

const result = findBestMatch("marselle", ["Paris", "Lyon", "Marseille"], {
  algorithm: "jaro-winkler"
});

result.bestMatch?.candidate;
// "Marseille"

createMatcher(candidates, defaultOptions?)

Creates a reusable matcher when you compare many queries against the same candidate list.

import { createMatcher } from "text-similarity-kit";

const matcher = createMatcher(["Open file", "Close file", "Save all"], {
  algorithm: "jaro-winkler",
  threshold: 0.2
});

matcher.rank("save");
matcher.findBest("close");

Lower-level helpers

import {
  diceCoefficient,
  getBigrams,
  jaroSimilarity,
  jaroWinklerSimilarity,
  levenshteinDistance,
  levenshteinSimilarity,
  normalizeText
} from "text-similarity-kit";

These helpers are useful when you need explicit control over the scoring algorithm.

Normalization options

All comparison APIs support the same normalization options:

compareStrings("Électricité", "electricite", {
  stripDiacritics: true,
  caseSensitive: false,
  trim: true,
  normalizeWhitespace: true,
  locale: "fr"
});

Defaults:

| Option | Default | | --- | --- | | caseSensitive | false | | trim | true | | normalizeWhitespace | true | | stripDiacritics | false |

Ranking options:

| Option | Default | | --- | --- | | threshold | 0 | | limit | no limit |

Jaro-Winkler options:

| Option | Default | | --- | --- | | prefixScale | 0.1 | | maxPrefixLength | 4 |

Choosing an algorithm

Use dice first for product labels, routes, titles and short records. It is fast, simple and usually good enough.

Use levenshtein when the number of edits is meaningful, for example typo checks.

Use jaro-winkler for names and identifiers where matching the beginning of the string should matter more.

Notes

  • This package is intended for short to medium strings, not semantic similarity or large document comparison.
  • Scores from different algorithms are not directly equivalent. Pick one algorithm for a workflow and tune the threshold for that algorithm.
  • The implementation is clean-room and does not copy code from the archived string-similarity package.

License

MPL-2.0