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

@cdimascio/fuzzy

v0.2.0

Published

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

Downloads

5

Readme

fuzzy Build Status npm version

1k standalone fuzzy search / fuzzy filter a la Sublime Text's command-p fuzzy file search. Works in both node and browser.

Example

Try it yourself: Disney Character Search Example

Get it

Node:

$ npm install --save fuzzy
$ node
> var fuzzy = require('fuzzy');
> console.log(fuzzy)
{ test: [Function],
  match: [Function],
  filter: [Function] }

Browser:

<script src="/path/to/fuzzy.js"></script>
<script>
  console.log(fuzzy);
  // Object >
  //   filter: function (pattern, arr, opts) {
  //   match: function (pattern, string, opts) {
  //   test: function (pattern, string) {
</script>

Use it

Padawan: Simply filter an array of strings.

var list = ['baconing', 'narwhal', 'a mighty bear canoe'];
var results = fuzzy.filter('bcn', list)
var matches = results.map(function(el) { return el.string; });
console.log(matches);
// [ 'baconing', 'a mighty bear canoe' ]

Jedi: Wrap matching characters in each string

var list = ['baconing', 'narwhal', 'a mighty bear canoe'];
var options = { pre: '<', post: '>' };
var results = fuzzy.filter('bcn', list, options)
console.log(results);
// [
//   {string: '<b>a<c>o<n>ing'           , index: 0, score: 3, original: 'baconing'},
//   {string: 'a mighty <b>ear <c>a<n>oe', index: 2, score: 3, original: 'a mighty bear canoe'}
// ]

Jedi Master: sometimes the array you give is not an array of strings. You can pass in a function that creates the string to match against from each element in the given array

var list = [
    {rompalu: 'baconing', zibbity: 'simba'}
  , {rompalu: 'narwhal' , zibbity: 'mufasa'}
  , {rompalu: 'a mighty bear canoe', zibbity: 'saddam hussein'}
];
var options = {
    pre: '<'
  , post: '>'
  , extract: function(el) { return el.rompalu; }
};
var results = fuzzy.filter('bcn', list, options);
var matches = results.map(function(el) { return el.string; });
console.log(matches);
// [ '<b>a<c>o<n>ing', 'a mighty <b>ear <c>a<n>oe' ]

Examples

Check out the html files in the examples directory.

Try the examples live:

Documentation

Code is well documented and the unit tests cover all functionality

Contributing

Fork the repo!

git clone <your_fork>
cd fuzzy
npm install
make

Add unit tests for any new or changed functionality. Lint, test, and minify using make, then shoot me a pull request.

Release History

v0.1.0 - July 25, 2012

  • Initial Release

v0.1.1 - September 19, 2015

  • Fix broken links in package.json
  • Fix examples

v0.1.2 - September 25, 2016

  • Exact matches get the highest score. #15
  • Add TypeScript typings #21
  • Better error handling for invalid input #13
  • Smaller bower install footprint #22

v0.1.3 - October 1, 2016

  • Fix blocking bug in React Native #27

License

Copyright (c) 2015 Matt York Licensed under the MIT license.

TODO

  1. Search improvement: behave a bit more like sublime text by getting the BEST match in a given string, not just the first. For example, searching for 'bass' in 'bodacious bass' should match against 'bass', but it currently matches like so: <b>od<a>ciou<s> ba<s>s. There is a test already written, just need to implement it. Naive O(n^2) worst case: find every match in the string, then select the highest scoring match. Should benchmark this against current implementation once implemented Also, "reactive rice" would be <r><e>active r<i><c>e
  2. Search feature: Work on multiple strings in a match. For example, be able to match against 'stth' against an object { folder: 'stuff', file: 'thing' }
  3. Async batch updates so the UI doesn't block for huge sets. Or maybe Web Workers?
  4. Performance performance performance!