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 🙏

© 2026 – Pkg Stats / Ryan Hefner

wess-react-filter-builder

v1.0.0

Published

A reusable, schema-driven React filter builder library with JSON serialization, validation, and API integration.

Downloads

2

Readme

React Filter Builder Library

A reusable, dataset-agnostic Filter Builder built with React + TypeScript.
It allows users to construct arbitrary nested filter conditions (and/or groups) and serialize them into JSON for server integration.

Supports:

  • Dynamic schemas (fields & operators configurable)
  • Type-aware inputs (string, number, boolean, date, array)
  • Validation rules
  • JSON serialization/deserialization
  • API integration (GET query string or POST JSON body)
  • Accessibility (ARIA, keyboard navigation, focus states)
  • Tailwind styling (lightweight, customizable)

Setup Instructions

1. Clone & Install

git clone https://github.com/Wess58/filter-builder-react.git
cd filter-builder
npm install

2. Run Dev Demo App

npm run dev

This launches the example playground with sample schemas.

Example Usage

import { FilterBuilder } from "filter-builder";
import { Schema, OperatorsMap } from "filter-builder/types";

// SCHEMA TYPE
const userSchema: Schema = {
  age: "number",
  role: "string",
  isActive: "boolean",
  createdAt: "date",
};

// SUPPORTED OPERATORS MAP
const operators: OperatorsMap = {
  string: ["eq", "neq", "contains", "starts_with", "ends_with", "in"],
  number: ["eq", "neq", "gt", "lt", "between"],
  boolean: ["eq", "neq"],
  date: ["eq", "neq", "before", "after", "between"],
};

export default function App() {
  return (
    <FilterBuilder
      schema={userSchema}
      operators={operators}
      apiConfig={{
        mode: "POST", // or "GET"
        url: "https://example.com/api/users",
        queryParam: "filters", // only used in GET mode
      }}
      onChange={(json) => console.log("Live JSON:", json)}
      onApply={(res) => console.log("API response:", res)}
    />
  );
}

Config API

schema: Schema

Defines available fields and their types.

type FieldType = "string" | "number" | "boolean" | "date";
type Schema = Record<string, FieldType>;
operators: OperatorsMap

Operators allowed per field type.

type OperatorsMap = {
  string: string[];
  number: string[];
  boolean: string[];
  date: string[];
};
initialJson?: any

Optional JSON to preload (deserialized into UI).

onChange?: (json: any | { error: string }) => void

Callback fired on every change:

  • Emits valid JSON when valid
  • Emits { error } when invalid
apiConfig?: { mode: "GET" | "POST"; url: string; queryParam?: string }

Optional auto-wiring to backend:

  • GET → serialized JSON as query string param
  • POST → serialized JSON in body
onApply?: (response: any) => void

Callback when Apply button is clicked and API call resolves.

Example JSON Output

{
  "and": [
    { "field": "age", "operator": "gt", "value": 25 },
    { "field": "role", "operator": "in", "value": ["admin", "user"] }
  ]
}

Architecture Choices

React + TypeScript

Provides type safety, schema validation and easy extensibility.

Schema-driven

Fields & operators are provided by config, making the library dataset-agnostic.

Recursive Tree Structure

Groups (and/or) can contain conditions or other groups. This allows deeply nested logical expressions.

Serialization & Deserialization

Filters can be saved as JSON, re-loaded and re-edited in the UI.

Validation

Inline validation rules enforce correct filter input:

  • between → requires two values
  • in → requires array of values
  • is null/is not null → require no value

Accessibility

ARIA roles, labels and focus styles make it usable with screen readers and keyboards.

Styling with Tailwind

Provides a clean baseline while remaining customizable.

Testing

Unit tests for utils (serialization, validation, API). Integration tests for user flows (add/edit/remove conditions, groups, apply filters).