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

@nexucis/fuzzy

v0.5.1

Published

small, standalone fuzzy search / fuzzy filter. browser or node

Downloads

48,564

Readme

Fuzzy

CircleCI codecov NPM version GitHub license

This lib provides a fuzzy search. It's inspired from the work of Matt York on the repository fuzzy

Installation

npm install @nexucis/fuzzy

Getting started

  1. Filter a simple list of string
import Fuzzy from '@nexucis/fuzzy'

const fuz = new Fuzzy()
const list = ['lion', 'goat', 'mouse', 'dragon']

console.log(fuz.filter('li', list))
// [
//   {rendered: 'lion', index: 0, score: 4, original: 'lion'},
// ]
//
  1. Wrap matching characters in each string for highlighting
import Fuzzy from '@nexucis/fuzzy'

const fuz = new Fuzzy({pre:'<b>', post:'</b>'})
const list = ['lion', 'goat', 'mouse', 'dragon']

console.log(fuz.filter('li', list))
// [
//   {rendered: '<b>li</b>on', index: 0, score: 4, original: 'lion'},
// ]
//
  1. Include the list of indices of the matched characters to make your own highlight
import Fuzzy from '@nexucis/fuzzy'

const fuz = new Fuzzy({includeMatches: true})
const list = ['lion', 'goat', 'mouse', 'dragon']

console.log(fuz.filter('li', list))
// [
//   {rendered: 'lion', index: 0, score: 4, original: 'lion', intervales:[{from:0, to:2}]},
// ]
//
  1. Override locally the global configuration
import Fuzzy from '@nexucis/fuzzy'

const fuz = new Fuzzy({includeMatches: true})
const list = ['lion', 'goat', 'mouse', 'dragon']

console.log(fuz.filter('li', list), {includeMatches: false})
// [
//   {rendered: 'lion', index: 0, score: 4, original: 'lion'},
// ]
//

Available Options

Note: each option can be passed to the constructor or/and in each method exposed. The options passed in the method take precedence over the one passed in the contructor.

caseSensitive

  • Type: boolean
  • Default: false

Indicates whether comparisons should be case-sensitive.

excludedChars

  • Type: array of string
  • Default: []

List of characters that should be ignored in the pattern or in the word used for matching

includeMatches

  • Type: boolean
  • Default: false

Whether the matches should be included in the result. When true, each record in the result set will include the indices of the matched characters. These can consequently be used for highlighting purposes.

shouldSort

  • Type: boolean
  • Default: false

Whether the result should be sorted

shouldRender

  • Type: boolean
  • Default: true

If true, then the strings matched will be automatically rendered using the config pre/post and escapeHTML.

In case you want to render it yourself, set it to false, and set includeMatches to true. You will need the intervals to call the method render.

escapeHTML

  • Type: boolean
  • Default: false

Whether the filtering should escape the HTML characters that can be found in each record in the result

pre

  • Type: string
  • Default: ''

Should be used to prefix each matched characters. Can be useful for the highlighting.

post

  • Type: string
  • Default: ''

Should be used to suffix each matched characters. Can be useful for the highlighting.

Contributions

Any contribution or suggestion would be really appreciated. Feel free to file an issue or send a pull request.

License

MIT