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

@art-suite/art-fuzzy-search

v0.1.5

Published

Easy, fast, fuzzy text search.

Downloads

16

Readme

ArtFuzzySearch

Easy, fast, fuzzy text search.

The primary use-case for ArtFuzzySearch is to quickly filter a list of items as you type, and to do it in flexible way so you catch odd spellings and type-os and other inconsistencies. The key to success is speed and, together with a good UX, interactively showing the results as the user types and edits their search string.

It works similar to VSCode and SublimeText's file-search. The order of the letters matter, but there can be missing letters or skipped letters.

Example

let {fuzzySearch} = require("@art-suite/art-fuzzy-search");

let result = fuzzySearch(
  "fz",       // search text
  [
    ["I love food"],
    "fz - just a string is OK too",
    ["I find pizza appealing", 123, true],
    ["I fuzzbuzz", "any extra data", "is returned unchanged"]
  ]
)

/*
result: [
  "fz - just a string is OK too",
  ["I fuzzbuzz", "any extra data", "is returned unchanged"],
  ["I find pizza appealing", 123, true]
];
*/

API

let {fuzzySearch} = require("@art-suite/art-fuzzy-search");

fuzzySearch(searchString, searchData) => filteredAndSortedSearchData
  • IN: (searchString, searchData)

    • searchString: an String to search for
    • searchData: [searchDataRecord, ...] (an Array of searchDataRecords)
  • OUT: searchData, filtered and sorted by best-matches

  • searchDataRecord: [searchInString, arbitraryData...]

    • searchDataRecords are themselves an array
    • only the first element is used by fuzzySearch
    • searchInString: arbitrary String which is tested to see if it matches the provided searchString; the quality of the match is also considered and used for the final sort of the returned searchData
    • arbitraryData: if searchInString matches, the entire searchDataRecord will be returned, untouched - including any arbitrary data included after searchInString. Use these additional slots to pass through any additional data you need. e.g. a JSON object of the record or just the record's ID.

Note that fuzzySearch is very forgiving. The only requirement for a match is that the characters of the searchString exist in the searchInString (case insensitively), in the same order, but possibly with any number of characters in between:

Example: If searchString == 'dog', then the string "I did a lot of great work." will match: "I Did a lOt of Great work."

The key is the results will be sorted based on the quality of the match - best match first. The main sorting criterias is the length of the match. Sorter matches are preferred. For more details, see the Algorithm Notes below.

Algorithm Notes

Basic algorithm:

  1. Filter out all search-texts that don't match:
    • all letters from the search string must be present and in the same order in the search text
    • However, they don't have to match case and they can optionally match search-text with extra characters in between. e.g. "fz" will match "Fun zoo" since "f" and "z" are in order even though "un " is in between.
  2. Sort the results by result-quality which is determined by
    • length of match; shorter is preferred
    • case sensitive matches are preferred
    • matches closer to the beginning of the search-text are preferred