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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@interstellarjay/multifilter

v1.1.1

Published

A simple opinionated library to help you apply multiple filters on JSON data. Lightweight and easy to use!

Downloads

8

Readme

MultiFilter

What is MultiFilter?

This is a open-source, free, library to apply multiple filters on JSON data. The library is designed to be lightweight, extensible and easy to use.

You can use this library to filter on combinations of:

  • Dates
  • Strings
  • Numbers
  • Booleans

100% Written in JavaScript.


How do I use MultiFilter?

Install the module from npm

npm i -S @interstellarjay/multifilter

Create a new MultiFilter instance

const MultiFilter = require("@interstellarjay/mutlifilter@latest");
const mf = new MultiFilter();

Fetch your JSON data

const dataSet = [
	{
		name: "Nintendo® Switch",
		age: 2
	},
	{
		name: "PlayStation® 4",
		age: 6
	},
	{
		name: "PS4® Pro",
		age: 3
	}
];

List your filters as shown below, you can use the preset filters in MultiFilter or write your own filter functions. Don't use parentheses ().

/**
 *	Store your conditions in an array of objects like this..
 *	-> filter takes a function (see MultiFilter helper functions)
 *	-> onProperty is the key in the object to use to validate.
 *	-> condition is the value that to use to validate.
 **/
let filters = [
	{
		filter: mf.filterLessThan,
		onProperty: "age"
		condition: 6,
	},
	{
		filter: mf.filterGreaterThan,
		onProperty: "age"
		condition: 2,
	}
];

Apply the filters

mf.applyFilters(filters);

Filter the JSON data with the applied filters

const result = mf.filter(dataSet);
console.log(result); // [{ name: "PS4® Pro", age: 3 }]

Clear the filters when you no longer need them.

mf.clearFilters();

Creating filters

In MultiFilter each filter is written in the following format.

{
	filter: FILTER_FUNCTION,
	onProperty: KEY_IN_EACH_OBJECT,
	condition: VALIDATE_AGAINST_THIS_VALUE
}

Then store all the filters you would like to apply in an array.

let filters = [
	{
		filter: mf.filterLessThan,
		onProperty: "age"
		condition: 6,
	},
	{
		filter: mf.filterGreaterThan,
		onProperty: "age"
		condition: 2,
	}
];

mf.applyFilters (Array of filters)

Registers all the filters to be used before the data is filtered.

mf.applyFilters(filters)


mf.clearFilters ()

Removes all the applied filters, your data will now be unfiltered.

mf.clearFilters()


mf.filter (JSON)

Filters the JSON with every filter from the mf.applyFilters(filters) function. Returns JSON of filtered data.

mf.filter(JSON)


MultiFilter comes with helper filter functions for testing against numbers, strings and booleans.

mf.filterLessThan Number

Filter everything < 70 from the weightKG key of every object in the JSON.

{
	filter: mf.filterLessThan,
	onProperty: "weightKG",
	condition: 100
}

mf.filterGreaterThan Number

Filter everything > 20 from the likes key of every object in the JSON.

{
	filter: mf.filterGreaterThan,
	onProperty: "likes",
	condition: 20
}

mf.filterEqualTo Number, String, Boolean

:warning: By default "-", and "_", and " " are escaped from strings.

Filter everything equal to "PlayStation" from the brand key of every object in the JSON.

{
	filter: mf.filterGreaterThan,
	onProperty: "brand",
	condition: "PlayStation"
}

mf.filterNotEqualTo Number, String, Boolean

:warning: By default "-", and "_", and " " are escaped from strings.

Filter everything not equal to "God of War" from the title key of every object in the JSON.

{
	filter: mf.filterGreaterThan,
	onProperty: "title",
	condition: "God of War"
}

mf.filterBeforeDate String as "YYYY-MM-DD"

Filter everything before October 5th 2019 from the launchdate key of every object in the JSON.

{
	filter: mf.filterGreaterThan,
	onProperty: "launchdate",
	condition: "2019-10-05",
}

mf.filterAfterDate String as "YYYY-MM-DD"

Filter everything after June 25th 2020 from the bookingdate key of every object in the JSON.

{
	filter: mf.filterGreaterThan,
	onProperty: "bookingdate",
	condition: "2020-06-25"
}

mf.filterEqualToDate String as "YYYY-MM-DD"

Filter everything equal to February 28th 2020 from the departuredate key of every object in the JSON.

{
	filter: mf.filterGreaterThan,
	onProperty: "departuredate",
	condition: "2020-02-18",
}

mf.filterNotEqualToDate String as "YYYY-MM-DD"

Filter everything not equal to March 3rd 2020 from the returndate key of every object in the JSON.

{
	filter: mf.filterGreaterThan,
	onProperty: "returndate",
	condition: "2020-03-01"
}

Where would I use this?

Filter your data set by name, release date, rating, color, price, age, condition... anything you like!


Why create MultiFilter?

MultiFilter was created because I felt like the process of applying multiple filters on JSON needed to be simpler.


Enjoying MultiFilter?

If you're enjoying MultiFilter and would like to support the project, please consider becoming a contributor.