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

fzi

v1.5.0

Published

fzy written in imba with some performance optimizations

Downloads

7

Readme

fzi

fzi is (probably) the fastest and most accurate JavaScript fuzzy searching algorithm. It is extremely effective for shorter strings like file paths. It is not very effective at searching long strings like paragraphs of prose.

Performance

fzi was forked from the excellent fzy.js, however fzi is much faster because it uses a 1D matrix representation and it only instantiates the score matrix once per import. fzi also has a replaceMatches function which is a much more performant way of replacing matches than using an array of matching positions.

fzi's api is also very convenient, coming with a search function that accepts an arbitrary iteratee and a replaceMatches function that accepts an arbitrary replace function. With other search algorithms, you either have to score every item yourself or create a class instance.

Installation

npm i fzi

Usage

All the following examples are written in a fantastic language called imba, which compiles to readable JavaScript.

search

fzi.search(needle, haystack, iteratee)

fzi.search takes a query, array, and an optional iteratee.

If an iteratee is not supplied, fzi.search will assume that it has been passed an array of strings.

Without iteratee:

import fzi from 'fzi'

let query = "f"

let array = [
	"first note"
	"second note"
]

let search_result = fzi.search query, array

With iteratee:

import fzi from 'fzi'

let query = "f"

let array = [
	{ content: "first note", id: 1 }
	{ content: "second note", id: 2 }
]

let iteratee = do $1.content

let search_result = fzi.search query, array, iteratee

fzi.search will silently skip any non-string elements, both with and without an iteratee.

replaceMatches

fzi.replaceMatches(needle, haystack, replaceMatch, replaceDiff)

This is a very performant and convenient way of replacing fuzzy matches in a string.

For example, to make all matches red in your terminal window:

# npm i colors
import 'colors'
let needle = "hlo"
let haystack = "hello"
fzi.replaceMatches(needle, haystack) do $1.red

Or to wrap each match with a <span>:

fzi.replaceMatches(needle, haystack) do "<span>{$1}</span>"

fzi.replaceMatchedRanges

This will pass adjacent matches as one string to the callback function, resulting in a cleaner output.

fzi.positions

Returns an array of matching positions. Probably not useful.