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

@nlptools/distance

v0.0.2

Published

Complete string distance and similarity algorithms package with WebAssembly and JavaScript implementations

Readme

@nlptools/distance

npm version npm downloads npm license Contributor Covenant

Complete string distance and similarity algorithms package with WebAssembly and JavaScript implementations

This package provides comprehensive text similarity and distance algorithms, combining the high-performance WebAssembly implementation from @nlptools/distance-wasm with additional JavaScript-based algorithms for maximum compatibility and performance.

Features

  • Dual Implementation: WebAssembly for performance + JavaScript for compatibility
  • 🧮 Comprehensive Algorithms: 30+ string similarity and distance algorithms
  • 🎯 Multiple Categories: Edit-based, sequence-based, token-based, and naive algorithms
  • 📝 TypeScript First: Full type safety with comprehensive API
  • 🔧 Universal Interface: Single compare function for all algorithms
  • 📊 Normalized Results: Consistent 0-1 similarity scores across algorithms
  • 🚀 Auto-optimization: Automatically chooses the fastest implementation available

Installation

# Install with npm
npm install @nlptools/distance

# Install with yarn
yarn add @nlptools/distance

# Install with pnpm
pnpm add @nlptools/distance

Usage

Basic Setup

import * as distance from "@nlptools/distance";

// All algorithms are available as named functions
console.log(distance.levenshtein("kitten", "sitting")); // 3
console.log(distance.jaro("hello", "hallo")); // 0.8666666666666667
console.log(distance.cosine("abc", "bcd")); // 0.6666666666666666

Distance vs Similarity

Most algorithms have both distance and normalized versions:

// Distance algorithms (lower is more similar)
const dist = distance.levenshtein("cat", "bat"); // 1

// Similarity algorithms (higher is more similar, 0-1 range)
const sim = distance.levenshtein_normalized("cat", "bat"); // 0.6666666666666666

Available Algorithms

This package includes all algorithms from @nlptools/distance-wasm plus additional JavaScript implementations:

Edit Distance Algorithms

  • levenshtein - Classic edit distance
  • fastest_levenshtein - High-performance Levenshtein distance (fastest-levenshtein)
  • damerau_levenshtein - Edit distance with transpositions
  • myers_levenshtein - Myers bit-parallel algorithm for edit distance
  • jaro - Jaro similarity
  • jarowinkler - Jaro-Winkler similarity
  • hamming - Hamming distance for equal-length strings
  • sift4_simple - SIFT4 algorithm

Sequence-based Algorithms

  • lcs_seq - Longest common subsequence
  • lcs_str - Longest common substring
  • ratcliff_obershelp - Gestalt pattern matching
  • smith_waterman - Local sequence alignment

Token-based Algorithms

  • jaccard - Jaccard similarity
  • cosine - Cosine similarity
  • sorensen - Sørensen-Dice coefficient
  • tversky - Tversky index
  • overlap - Overlap coefficient

Bigram Algorithms

  • jaccard_bigram - Jaccard similarity on character bigrams
  • cosine_bigram - Cosine similarity on character bigrams

Naive Algorithms

  • prefix - Prefix similarity
  • suffix - Suffix similarity
  • length - Length-based similarity

Universal Compare Function

const result = distance.compare("hello", "hallo", "jaro");
console.log(result); // 0.8666666666666667

// Use fastest-levenshtein for optimal performance
console.log(distance.fastest_levenshtein("fast", "faster")); // 2

Performance

The package automatically selects the fastest implementation available:

  • WebAssembly algorithms: 10-100x faster than pure JavaScript
  • Auto-detection: Seamlessly switches between WASM and JS implementations

References

This package incorporates and builds upon the following excellent open source projects:

License