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

typo-tolerance-synonyms

v1.0.1

Published

This package provides an advanced multilingual search engine with phonetic matching and extensive language support, designed to filter input for typographical errors and return refined search results.

Readme

typo-tolerance-synonyms

An advanced search package that provides typo tolerance, automatic synonym detection, phonetic matching, and multi-language support. Perfect for e-commerce sites, content management systems, and search applications.

npm version License

Features

  • 🔍 Advanced typo tolerance using Levenshtein distance
  • 🎯 Automatic synonym detection
  • 🔊 Phonetic matching support
  • 🌍 Multi-language support
  • ⚡ High-performance caching
  • 📝 Customizable scoring system
  • 🎮 Perfect for e-commerce and product search

Installation

npm install typo-tolerance-synonyms

Basic Usage

const { TypoTolerantSearch } = require('typo-tolerance-synonyms');

async function searchExample() {
    const search = new TypoTolerantSearch({
        typoTolerance: 2,
        usePhonetic: true,
        languages: ['eng', 'afr'] // English and Afrikaans support
    });

    const results = await search.search('gaming mouse', products);
    console.log(results);
}

Gaming Accessories Example (English & Afrikaans)

const { TypoTolerantSearch } = require('typo-tolerance-synonyms');

async function gamingSearchExample() {
    // Initialize the search engine
    const search = new TypoTolerantSearch({
        typoTolerance: 2,
        usePhonetic: true,
        languages: ['eng', 'afr']
    });

    // Sample gaming accessories database
    const products = [
        // English entries
        'Gaming Mouse RGB Wireless',
        'Professional Gaming Keyboard',
        'Gaming Headset with Microphone',
        'RGB Mousepad XL Size',
        'Controller for PC Games',
        // Afrikaans entries
        'Speletjie Muis Draadloos',  // Gaming Mouse Wireless
        'Professionele Sleutelbord',  // Professional Keyboard
        'Kopfoon met Mikrofoon',      // Headphone with Microphone
        'Muismat Groot Grootte',      // Mousepad Large Size
        'Beheerder vir Rekenaarspeletjies' // Controller for Computer Games
    ];

    // Example 1: Search with typo (English)
    const typoSearch = await search.search('gaming mose wireless', products);
    console.log('Typo Search Results:');
    console.log(typoSearch);
    // Output will include:
    // - Gaming Mouse RGB Wireless
    // - Speletjie Muis Draadloos
    // (with relevance scores)

    // Example 2: Search in Afrikaans with typo
    const afrikaansSearch = await search.search('spelietje muiz', products, {
        language: 'afr'
    });
    console.log('Afrikaans Search Results:');
    console.log(afrikaansSearch);
    // Output will include:
    // - Speletjie Muis Draadloos
    // - Gaming Mouse RGB Wireless
    // (with relevance scores)

    // Example 3: Phonetic search
    const phoneticSearch = await search.search('geiming hedset', products);
    console.log('Phonetic Search Results:');
    console.log(phoneticSearch);
    // Will match both English and Afrikaans headset entries
}

gamingSearchExample();

Advanced Configuration

const search = new TypoTolerantSearch({
    // Basic settings
    typoTolerance: 2,              // Maximum number of character differences allowed
    caseSensitive: false,          // Case sensitivity
    usePhonetic: true,             // Enable phonetic matching
    
    // Language settings
    languages: ['eng', 'afr'],     // Supported languages
    
    // Scoring weights
    weights: {
        exact: 1.0,                // Exact match weight
        synonym: 0.9,              // Synonym match weight
        phonetic: 0.8,             // Phonetic match weight
        typo: 0.7                  // Typo tolerance weight
    }
});

API Reference

Constructor Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | typoTolerance | number | 2 | Maximum allowed character differences | | caseSensitive | boolean | false | Enable case-sensitive search | | usePhonetic | boolean | true | Enable phonetic matching | | languages | string[] | ['eng'] | Supported languages | | weights | object | {...} | Scoring weights configuration |

Methods

search(searchText, targetArray[, options])

Performs a search with typo tolerance and synonym support.

const results = await search.search('gaming headfones', products, {
    language: 'eng',
    threshold: 0.3
});

Parameters:

  • searchText: String to search for
  • targetArray: Array of strings to search in
  • options: Optional configuration object
    • language: Force specific language processing
    • threshold: Minimum score threshold (0-1)

Returns: Array of matches with scores:

[
    {
        text: "Gaming Headset with Microphone",
        score: 0.95,
        language: "eng",
        matches: 2
    },
    // ...more results
]

getPhoneticCodes(word)

Get phonetic codes for a word using multiple algorithms.

const codes = search.getPhoneticCodes('gaming');
// Returns: { metaphone: 'GMNG', doubleMetaphone: ['KMNK', 'KMNK'], soundex: 'G552' }

Language Support

Currently supported languages:

  • English (eng)
  • Afrikaans (afr)

Each language includes:

  • Language-specific synonym detection
  • Stopword filtering
  • Diacritic handling
  • Custom text normalization

Performance Tips

  1. Caching: The package automatically caches synonym and phonetic results
  2. Batch Processing: Process multiple searches in parallel using Promise.all
  3. Language Detection: Specify language when known for better performance

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see LICENSE for details

Support

Changelog

Version 1.0.0

  • Initial release with typo tolerance and multi-language support
  • English and Afrikaans language support
  • Phonetic matching implementation
  • Automatic synonym detection