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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@nivalis/string-similarity

v5.2.0

Published

Finds degree of similarity between strings, based on Dice's Coefficient, which is mostly better than Levenshtein distance.

Readme

@nivalis/string-similarity

String similarity helpers powered by Dice's coefficient. Use it to rank fuzzy matches, measure duplicate content, or power smart suggestions with predictable, deterministic scoring.

Highlights

  • Modern TypeScript codebase with typed ESM builds
  • Fast O(n) bigram comparison implementation
  • Zero dependencies and side-effect free for optimal tree shaking
  • Works anywhere a JavaScript runtime with ES2020 support is available

Installation

# pick the package manager you prefer
bun add @nivalis/string-similarity
# or
npm install @nivalis/string-similarity
# or
pnpm add @nivalis/string-similarity

The package is ESM-only. Use Node.js 18+, Bun, Deno, or a bundler that understands ESM.

Quick Start

import { compareTwoStrings, findBestMatch } from '@nivalis/string-similarity';

const similarity = compareTwoStrings('healed', 'sealed');
// similarity === 0.8

const { ratings, bestMatch } = findBestMatch('healed', [
  'mailed',
  'sealed',
  'theatre',
]);

/* ratings === [
  { target: 'mailed', rating: 0.4 },
  { target: 'sealed', rating: 0.8 },
  { target: 'theatre', rating: 0.36363636363636365 },
] */
/* bestMatch === { target: 'sealed', rating: 0.8 } */

API

compareTwoStrings(first: string, second: string): number

Returns a score between 0 and 1. Whitespace is stripped before comparison and the order of arguments does not matter.

  • first / second: Strings with at least two characters for the best signal
  • Returns: number similarity score
compareTwoStrings('french', 'quebec');
// 0
compareTwoStrings('Olive-green table for sale, in extremely good condition.',
  'For sale: table in very good condition, olive green in colour.');
// 0.6060606060606061

findBestMatch(mainString: string, targetStrings: string[])

Evaluates every entry in targetStrings and returns:

  • ratings: ordered array of { target: string, rating: number }
  • bestMatch: the record with the highest rating
  • bestMatchIndex: the index of bestMatch inside targetStrings
const result = findBestMatch('Olive-green table for sale, in extremely good condition.', [
  'For sale: green Subaru Impreza, 210,000 miles',
  'For sale: table in very good condition, olive green in colour.',
  'Wanted: mountain bike with at least 21 gears.',
]);

result.bestMatch.target;
// 'For sale: table in very good condition, olive green in colour.'

Invalid arguments throw an error. Pass a non-empty mainString and a non-empty array of strings.

Algorithm Notes

  • Based on bigram overlap (Dice coefficient) for predictable rankings
  • Ignores whitespace and repeated bigrams to reduce noise
  • Complexity is O(n) relative to total input length, making it suitable for realtime UI filtering

Development

bun install        # install dependencies
bun test           # run the Bun test suite
bun run lint       # biome static analysis
bun run build      # compile to dist/ via tsdown

Automated hooks are managed by Lefthook. See CONTRIBUTING.md for detailed workflows, branch strategy, and release guidance.

Roadmap

  • Export an async/bulk API that can precompute bigrams for a target list and reuse them across multiple queries, reducing redundant work for search or autocomplete scenarios.

Release Notes

5.0.0

  • Converted the library to TypeScript and ESM-only exports
  • Switched to named exports compareTwoStrings and findBestMatch
  • Removed UMD/browser bundles in favor of modern bundler workflows

License

MIT © Nivalis Studio