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

didyoumean2

v7.0.4

Published

a library for matching human-quality input to a list of potential matches using the Levenshtein distance algorithm

Downloads

556,171

Readme

didyoumean2

Build Status codecov.io

node npm npm

didyoumean2 is a library for matching human-quality input to a list of potential matches using the Levenshtein distance algorithm. It is inspired by didyoumean.js.

Why reinventing the wheel

  1. Based on fastest-levenshtein, the fastest JS implementation of the Levenshtein distance algorithm

  2. ~100% faster than didyoumean.js

  3. Well tested with 100% coverage

  4. Static type checking with TypeScript

  5. More control on what kind of matches you want to return

  6. Support matching object's path instead of just key

Installation

npm install didyoumean2
const didYouMean = require('didyoumean2').default
// or if you are using TypeScript or ES module
import didYouMean from 'didyoumean2'

// you can also access to Enums via:
const {
  default: didYouMean,
  ReturnTypeEnums,
  ThresholdTypeEnums,
} = require('didyoumean2')
// or
import didYouMean, { ReturnTypeEnums, ThresholdTypeEnums } from 'didyoumean2'

Development Setup

We are using corepack to manage the yarn version

corepack enable

Usage

didYouMean(input, matchList[, options])
  • input {string}: A string that you are not sure and want to match with matchList

  • matchList {Object[]|string[]}: A List for matching with input

  • options {Object}(optional): An options that allows you to modify the behavior

  • @return {Array|null|Object|string}: A list of or single matched result(s), return object if match is {Object[]}

Options

caseSensitive {boolean}

  • default: false

  • Perform case-sensitive matching

deburr {boolean}

matchPath {Array}

  • default: []

  • If your matchList is an array of object, you must use matchPath to point to the string that you want to match

  • Refer to ramda R.path for how to define the path, e.g. ['obj', 'array', 0, 'key']

returnType {string}

  • default: ReturnTypeEnums.FIRST_CLOSEST_MATCH

| returnType | Description | | ------------------------------------- | ----------------------------------------------------------------- | | ReturnTypeEnums.ALL_CLOSEST_MATCHES | Return all matches with the closest value to the input in array | | ReturnTypeEnums.ALL_MATCHES | Return all matches in array | | ReturnTypeEnums.ALL_SORTED_MATCHES | Return all matches in array, sorted from closest to furthest | | ReturnTypeEnums.FIRST_CLOSEST_MATCH | Return first match from ReturnTypeEnums.ALL_CLOSEST_MATCHES | | ReturnTypeEnums.FIRST_MATCH | Return first match (FASTEST) |

threshold {integer|number}

  • depends on thresholdType

  • type: {number} (similarity) or {integer} (edit-distance)

  • default: 0.4 (similarity) or 20 (edit-distance)

  • If the result is larger (similarity) or smaller (edit-distance) than or equal to the threshold, that result is matched

thresholdType {string}

  • default: ThresholdTypeEnums.SIMILARITY

| thresholdType | Description | | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | | ThresholdTypeEnums.EDIT_DISTANCE | Refer to Levenshtein distance algorithm, must be integer, lower value means more similar | | ThresholdTypeEnums.SIMILARITY | l = max(input.length, matchItem.length), similarity = (l - editDistance) / l, number from 0 to 1, higher value means more similar |

trimSpaces {boolean}

  • default: true

  • Remove noises when matching

  • Trim all starting and ending spaces, and concatenate all continuous spaces to one space

Test

Before all:

npm install -g yarn
yarn install

Unit test and coverage:

yarn test

Linter:

yarn lint