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

fuzzy-array-filter

v0.1.5

Published

A simple fuzzy array prototype filter

Downloads

14

Readme

fuzzy-array-filter

npm version

A simple fuzzy filter function for array.prototype.filter using fuse.js.

Install

npm i -S fuzzy-array-filter

How to use it : Simple data structure

Basics

use this wrapper with simple array [val1, val2, ...] il is really (really) easy :

ìmport fuzzyFilter from 'fuzzy-array-filter';

const array = ['There is a house in New Orleans',
  'They call the Rising Sun',
  'And \'s been the ruin of many a poor boy',
  'And God, I know I\'m one',
  'My mother was a tailor',
  'She sewed my new blue jeans',
  'My father was a gamblin man',
  'Down in New Orleans',
  'Now the only thing a gambler needs',
  'Is a suitcase and trunk',
  'And the only time he\'s satisfied',
  'Is when he\'s on a drunk',
  'Oh mother, tell your children',
  'Not to do what I have done',
  'Spend your lives in sin and misery',
  'In the House of the Rising Sun' ];

console.log(array.filter(fuzzyFilter('new orleans')));
// => [ 'There is a house in New Orleans', 'Down in New Orleans' ]

Default fuzzy options are

{
  "threshold": 0.4,
  "location": 0,
  "distance": 100,
  "maxPatternLength": 32,
  "keys": []
}

With custom options

ìmport fuzzyFilter from 'fuzzy-array-filter';

const array = theRisingSunArray; // the previous one

const options = {
  caseSensitive: true,
};

console.log(array.filter(fuzzyFilter('new orleans', options)));
// => []

console.log(array.filter(fuzzySearch('man', options)));
// => [ 'And \'s been the ruin of many a poor boy', 'My father was a gamblin man' ]

For more details, please see the fuse.js options documentation

How to use it : More complex data structures

Basics

When you use this wrapper with more complex data structure, make sure you have provided some custom options. You MUST fill the id and the keys options.

id option is a single value. It can represent anything, like a string or a number.

Simple complex

const array = [
  { uniqueValue: 1, names: 'Edwina' },
  { uniqueValue: 2, names: 'Augusta' },
  { uniqueValue: 3, names: 'Lina' },
  { uniqueValue: 4, names: 'Ware' },
  { uniqueValue: 5, names: 'Kim' },
  { uniqueValue: 6, names: 'Nita' },
  { uniqueValue: 7, names: 'Garrett' },
  { uniqueValue: 8, names: 'Concepcion' },
  { uniqueValue: 9, names: 'Laverne' },
  { uniqueValue: 10, names: 'Alford' },
  { uniqueValue: 11, names: 'Jill' },
  { uniqueValue: 12, names: 'Reed' },
  { uniqueValue: 13, names: 'Shaw' },
];

const options = {
  keys: ['names'],
  id: 'uniqueValue'
}

const filteredArray = array.filter(fuzzyFilter('in', options))
console.log(filteredArray)

Complex

const array2 = [
  { id: 1, names: { first: 'Edwina', last:'random' } },
  { id: 2, names: { first: 'Augusta', last:'random' } },
  { id: 3, names: { first: 'Lina', last:'random' } },
  { id: 4, names: { first: 'Ware', last:'random' } },
  { id: 5, names: { first: 'Kim', last:'random' } },
  { id: 6, names: { first: 'Nita', last:'random' } },
  { id: 7, names: { first: 'Garrett', last:'random' } },
  { id: 8, names: { first: 'Concepcion', last:'random' } },
  { id: 9, names: { first: 'Laverne', last:'random' } },
  { id: 10, names: { first: 'Alford', last:'random' } },
  { id: 11, names: { first: 'Jill', last:'random' } },
  { id: 12, names: { first: 'Reed', last:'random' } },
  { id: 13, names: { first: 'Shaw', last:'random' } },
];

const options2 = {
  keys: ['names.first', 'names.last'],
  id: 'id'
}

const filteredArray2 = array2.filter(fuzzyFilter('in', options2))
console.log(filteredArray2)

More complex

const array3 = [
  { id: 1, names: { first: ['Edwina'], last:['random'] } },
  { id: 2, names: { first: ['Augusta'], last:['random'] } },
  { id: 3, names: { first: ['Lina'], last:['random'] } },
  { id: 4, names: { first: ['Ware'], last:['random'] } },
  { id: 5, names: { first: ['Kim'], last:['random'] } },
  { id: 6, names: { first: ['Nita'], last:['random'] } },
  { id: 7, names: { first: ['Garrett'], last:['random'] } },
  { id: 8, names: { first: ['Concepcion'], last:['random'] } },
  { id: 9, names: { first: ['Laverne'], last:['random'] } },
  { id: 10, names: { first: ['Alford'], last:['random'] } },
  { id: 11, names: { first: ['Jill'], last:['random'] } },
  { id: 12, names: { first: ['Reed'], last:['random'] } },
  { id: 13, names: { first: ['Shaw'], last:['random'] } },
];

const options3 = {
  keys: ['names.first'],
  id: 'id'
}

const filteredArray3 = array3.filter(fuzzyFilter('in', options3))
console.log(filteredArray3)

Dependencies

ToDo

  • Any idea ?