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-phrase-classifier

v1.1.1

Published

A small utility for fuzzy string searching where you provide strings and phrases, and receive the best fit results.

Downloads

23

Readme

fuzzy-phrase-classifier npm version TypeScript License: MIT

Types | Functions

  • getBestFitForAll()
  • applyBestFitForAll()
  • Phrase
  • PhrasedResult
  • Phraseable

getBestFitForAll(strings: string[], phrases: Phrase[]): PhrasedResult[]

Function that takes strings and the phrases to be used in comparison and will return the best fit results.

| Parameter | Description | | -------- | ----------- | | strings | Is compared with each phrase in @phrases parameter | | phrases | Contains the pattern and phraseName objects that the @strings will be classified to |

import { Phrase, getBestFitForAll } from "fuzzy-phrase-classifier";

const strings = [
  "The i o of the World",
  "The good Hunt",
  "The Dragqueen Reborn",
  "What Great Hunt?",
  "The iye of what Word?"
];

const phrases: Phrase[] = [
  { 
    "PhraseName": "The first book in the series",
    "Pattern": "The Eye of the World" 
  },    
  { 
    "PhraseName": "The second book in the series",
    "Pattern": "The Great Hunt" 
  },
  { 
    "PhraseName": "The third book in the series",
    "Pattern": "The Dragon Reborn" 
  }
];

console.log(getBestFitForAll(strings, phrases));

applyBestFitForAll(phraseables: Phraseable[], phrases: Phrase[]): void

Function that takes Phraseable objects and the phrases to be used in comparisons and will apply the best fit results into the appropriate properties of the working Phraseable object.

| Parameter | Description | | -------- | ----------- | | phraseables | Is compared with each phrase in the @phrases parameter using it's text property | | phrases | Contains the pattern and phraseName objects that the @phraseables will be classified to |

import { applyBestFitForAll } from "fuzzy-phrase-classifier";

const strings = [
  "The i o of the World",
  "The good Hunt",
  "The Dragqueen Reborn",
  "What Great Hunt?",
  "The iye of what Word?"
];

const phrases: Phrase[] = [
  { 
    "PhraseName": "The first book in the series",
    "Pattern": "The Eye of the World" 
  },    
  { 
    "PhraseName": "The second book in the series",
    "Pattern": "The Great Hunt" 
  },
  { 
    "PhraseName": "The third book in the series",
    "Pattern": "The Dragon Reborn" 
  }
];

class ExampleClass {
  text; // Raw text to be used in comparisons
  score; // Best score result
  bestFitPhrase; // Best fit phrase string

  constructor(text) {
    this.text = text;
  }
}

const phraseables = strings.map(text => new ExampleClass(text));

phraser.applyBestFitForAll(phraseables, phrases);
console.log(phraseables);

Phrase: interface

The Phrase interface is a structure that defines a phraseName and a pattern required for the fuzzy string searching.

| Property | Description | | -------- | ----------- | | PhraseName | Name of the phrase | | Pattern | String to be searched and matched with |

PhrasedResult: class

The PhraseResult class is used to contain the results from a fuzzy string search.

| Property | Description | | -------- | ----------- | | index | Index of the text in the original collection | | bestFitPhrase | Best fit phrase identifier | | score | Decimal number from 0 to 1 like a percentage showing how sure the algorithm was of the match | | text | Reference to the text this PhrasedResult correlates to |

Phraseable: interface

The Phraseable interface is a structure that defines text, score, and bestFitPhrase properties for use.

| Property | Data Flow | Description | | -------- | ----- | ----------- | | text | in | Text that will be used in comparisons for this object | | bestFitPhrase | out | Best fit phrase identifier | | score | out | Decimal number from 0 to 1 like a percentage showing how sure the algorithm was of the match |

Dependencies