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 🙏

© 2024 – Pkg Stats / Ryan Hefner

fuzzy-dist

v0.0.2

Published

Over simplistic fuzzy search library using Damerau-Levenshtein and optionally the keyboard layout to calculate distances.

Downloads

17

Readme

FuzzyDist

FuzzyDist is a simple tool for calculating the Damerau-Levenshtein distance between two strings. This class also supports optional keyboard-specific distance calculations, allowing for more nuanced distance measurements based on the layout of different keyboards.

Installation

npm install fuzzy-dist

Usage

1. Basic Damerau-Levenshtein Distance Calculation

To calculate the standard Damerau-Levenshtein distance between two strings, simply instantiate the FuzzyDist class without specifying a keyboard layout.

import FuzzyDist from 'fuzzy-dist';

const fuzzyDist = new FuzzyDist();
const distance = fuzzyDist.calculateDistance('kitten', 'sitten');
console.log(distance); // Outputs: 1

2. Damerau-Levenshtein Distance with Keyboard Layout Consideration

To include keyboard distance in the Damerau-Levenshtein calculation, you can specify a keyboard layout when instantiating the FuzzyDist class. This will add an additional layer of accuracy by taking into account the physical distance between keys on a specified keyboard.

import FuzzyDist from 'fuzzy-dist';

const fuzzyDistQwerty = new FuzzyDist(FuzzyDist.QwertyKeyboard);
const distance = fuzzyDistQwerty.calculateDistance('kitten', 'sitten');
console.log(distance); // Outputs: 2

const distanceWithKeyboard = fuzzyDistQwerty.calculateDistance('kitten', 'oitten');
console.log(distanceWithKeyboard); // Outputs: 1.4

const distanceWithKeyboard = fuzzyDistQwerty.calculateDistance('kitten', 'jitten');
console.log(distanceWithKeyboard); // Outputs: 1

3. Finding the Minimum Distance from a List of Strings

The FuzzyDist class also provides a method to find the closest match to a target string from an array of strings.

import FuzzyDist from './FuzzyDist';

const fuzzyDist = new FuzzyDist(FuzzyDist.QwertyKeyboard);
const target = 'hello';
const strings = ['hallo', 'hullo', 'hero', 'hell'];

const minDistance = fuzzyDist.getMinimumDistance(target, strings);
console.log(minDistance); // Outputs the minimum distance, e.g., 1

Keyboard Layout Options

The FuzzyDist class supports the following keyboard layouts:

  • FuzzyDist.QwertyKeyboard: QWERTY keyboard layout
  • FuzzyDist.QwertzKeyboard: QWERTZ keyboard layout (common in Germany)
  • FuzzyDist.AzertyKeyboard: AZERTY keyboard layout (common in France)
  • FuzzyDist.TurkishFKeyboard: Turkish F keyboard layout
  • FuzzyDist.InScriptKeyboard: InScript keyboard layout (common in India)

Constructor

constructor(keyboardId: number | null | undefined = null)
  • keyboardId: The identifier for the keyboard layout to use. If null, the standard Damerau-Levenshtein distance is calculated without considering keyboard layout.

Methods

calculateDistance(s1: string, s2: string): number

Calculates the Damerau-Levenshtein distance between two strings, optionally considering keyboard layout if specified in the constructor.

getMinimumDistance(target: string, strings: string[]): number

Finds and returns the minimum Damerau-Levenshtein distance between a target string and an array of strings.

License

MIT © Remotal