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

string-similarity-lite-ts

v1.0.0

Published

Ultra-fast (<1 KB), zero-dependency string similarity, Levenshtein edit distance, and fuzzy match finder.

Readme

🔍 string-similarity-lite-ts

Ultra-fast (< 1 KB), zero-dependency string similarity calculator, Levenshtein edit distance metric, and fuzzy best-match search for TypeScript and JavaScript.

npm version License: MIT Sponsor TypeScript Size


💡 Why string-similarity-lite-ts?

Applications often need quick typo tolerance, autocomplete suggestions, deduplication, or search queries without loading heavy fuzzy search libraries like Fuse.js (15 KB+) or outdated CommonJS-only modules.

string-similarity-lite-ts provides:

  • ⚡ Zero Dependencies — Pure native TypeScript, minified to less than 1 KB.
  • 📐 Dual Metric Suite — Computes Dice's Coefficient (normalized 0.0 to 1.0 ratio) and classical Levenshtein Edit Distance.
  • 🎯 Best Match Ranking — Instantly score a list of candidate strings against a query with findBestMatch().
  • 🔠 Configurable Case Sensitivity — Case-insensitive by default with full Unicode character safety.
  • 📦 Dual ESM & CommonJS — Native compatibility in Node.js, Next.js, Vite, React Native, and edge workers.

📥 Installation

# npm
npm install string-similarity-lite-ts

# pnpm
pnpm add string-similarity-lite-ts

# yarn
yarn add string-similarity-lite-ts

# bun
bun add string-similarity-lite-ts

🚀 Usage & Real-World Examples

1. Measuring Similarity Between Two Strings

import { stringSimilarity } from 'string-similarity-lite-ts';

// 1.0 means exact match, 0.0 means completely dissimilar
const score1 = stringSimilarity('hello world', 'hello world');
console.log(score1); // 1.0

const score2 = stringSimilarity('typescript', 'type-script');
console.log(score2); // 0.8889

const score3 = stringSimilarity('apple', 'banana');
console.log(score3); // 0.0

2. Levenshtein Edit Distance

Measures the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into another:

import { levenshteinDistance } from 'string-similarity-lite-ts';

console.log(levenshteinDistance('kitten', 'sitting')); // 3
console.log(levenshteinDistance('react', 'reach'));    // 1
console.log(levenshteinDistance('antigravity', 'antigravity')); // 0

3. "Did you mean?" Autocomplete & Fuzzy Suggestion

Find the closest match from a collection of command names or dictionary keywords:

import { findBestMatch } from 'string-similarity-lite-ts';

const availableCommands = [
  'install',
  'init',
  'publish',
  'test',
  'build',
  'deploy',
];

const userInput = 'publsih'; // Typo!

const result = findBestMatch(userInput, availableCommands);

console.log(`Did you mean "${result.bestMatch.target}"? (Score: ${result.bestMatch.rating})`);
// Output: Did you mean "publish"? (Score: 0.8333)

// Inspect full scored list:
console.log(result.ratings);

📖 API Reference

stringSimilarity(a, b, options?)

Calculates Dice's Coefficient score between two strings.

  • Parameters:
    • a (string): First string.
    • b (string): Second string.
    • options (SimilarityOptions, optional):
      • caseSensitive (boolean, default: false): Whether matching respects character casing.
  • Returns: number between 0.0 and 1.0.

levenshteinDistance(a, b)

Calculates edit operations between two strings.

  • Parameters:
    • a (string): First string.
    • b (string): Second string.
  • Returns: number (integer representing edit distance).

findBestMatch(target, candidates, options?)

Scores each string in candidates against target and returns the top match.

  • Parameters:
    • target (string): The query string.
    • candidates (string[]): Array of strings to compare against.
    • options (SimilarityOptions, optional).
  • Returns: BestMatchResult:
    interface BestMatchResult {
      ratings: { target: string; rating: number }[];
      bestMatch: { target: string; rating: number };
      bestMatchIndex: number;
    }

💖 Support the Project

If string-similarity-lite-ts made search and input correction faster in your apps, please consider sponsoring:

👉 Sponsor @Piratha97 on GitHub Sponsors


📄 License

MIT © 2026 Pirapaakaran Pirathapan