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

furry-text-search

v0.5.2

Published

A very simple furry/fuzzy text search library based on Fuse.js

Downloads

7

Readme

furry-text-search

NPM Version

furry-text-search is a library written in TypeScript to handle furry/fuzzy, imprecise, forgiving text search. It is based on Fuse.js albeit greatly simplified, and converted to proper TypeScript.

This library is probably not for everyone. I forked it specifically to use in a project where I needed a library like Fuse.js, but didn't need all of its features.

If you need more advanced features, there's a good chance you shouldn't be using this library lol

How to use

(The same code sample is also available in example.ts)

import { FurryIndex } from "./dist";

type BusLine = {
  routeShortName: string;
  agencyId: number;
  cities: string[];
};

type TransitAgency = {
  agencyId: number;
  agencyName: string;
};

// some example data
const agencies: Record<number, TransitAgency> = {
  1: {
    agencyId: 1,
    agencyName: "Egged",
  },
  2: {
    agencyId: 2,
    agencyName: "Dan",
  },
  3: {
    agencyId: 3,
    agencyName: "Metropoline",
  },
};

const lines: BusLine[] = [
  {
    routeShortName: "74",
    agencyId: 1,
    cities: ["Tel Aviv - Yafo", "Rishon LeZion", "Azor"],
  },
  {
    routeShortName: "201",
    agencyId: 1,
    cities: [
      "Tel Aviv - Yafo",
      "Azor",
      "Rishon LeZion",
      "Rehovot",
      "Nes Ziona",
    ],
  },
  {
    routeShortName: "1",
    agencyId: 2,
    cities: [
      "Bat Yam",
      "Tel Aviv - Yafo",
      "Ramat Gan",
      "Bney Brak",
      "Petah Tikva",
    ],
  },
  {
    routeShortName: "25",
    agencyId: 2,
    cities: ["Holon", "Bat Yam", "Tel Aviv - Yafo"],
  },
  {
    routeShortName: "24",
    agencyId: 3,
    cities: ["Ramat HaSharon", "Tel Aviv - Yafo"],
  },
];

// create an index to search through
const searchIndex = new FurryIndex<BusLine>(
  // the data to search through
  lines,

  // the fields we allow searching through, and their weight in scoring
  [
    {
      get: (line) => line.routeShortName,
      weight: 1,
    },
    {
      get: (line) => agencies[line.agencyId]?.agencyName ?? "",
      weight: 0.1,
    },
    {
      get: (line) => line.cities,
      weight: 0.1,
    },
  ],

  // how to sort search results
  (a, b) => {
    if (a.score === b.score) {
      return a.obj.routeShortName.localeCompare(b.obj.routeShortName);
    } else {
      return a.score - b.score;
    }
  },
);

// run a search:
const result = searchIndex.search(
  // we don't have any cities with "Ramot" in the name,
  // but we DO have cities with "Ramat" in the name!
  ["Ramot"],

  // this threshold value was reached through trial and error sorry :<
  0.35,

  // don't return things that don't match
  false,
);

console.log(result);

// value of result:
[
  {
    furrySearchResult: true,
    isMatch: true,
    idx: 2,
    obj: {
      routeShortName: "1",
      agencyId: 2,
      cities: [
        "Bat Yam",
        "Tel Aviv - Yafo",
        "Ramat Gan",
        "Bney Brak",
        "Petah Tikva",
      ],
    },
    score: 0.8744852722211678,
    matches: [
      [], // no matches in first field (routeShortName)
      [], // no matches in second field (agencyName)
      [
        // matches in third field (cities)
        null, // no matches in first item ("Bat Yam")
        null, // no matches in second item ("Tel Aviv - Yafo")
        [
          // matches in third item ("Ramat Gan")
          [0, 3], // characters 0 through 3 ("Rama")
        ],
      ],
    ],
  },
  {
    furrySearchResult: true,
    isMatch: true,
    idx: 4,
    obj: {
      routeShortName: "24",
      agencyId: 3,
      cities: ["Ramat HaSharon", "Tel Aviv - Yafo"],
    },
    score: 0.8744852722211678,
    matches: [[], [], [[0, 3]]],
  },
];