Skip to main content

filter-def

Easy, type-safe data filters in TypeScript. Define your filters once and get full type inference for filter inputs and results across in-memory arrays, Drizzle ORM, and BigQuery.

Key Features

Type-Safe

Full TypeScript inference for filter inputs and entity fields. Catch errors at compile time, not runtime.

Multi-Backend

Use the same filter patterns for in-memory arrays, Drizzle ORM, or BigQuery with zero lock-in.

Composable

Combine filters with AND/OR boolean logic to build complex queries from simple building blocks.

Extensible

Define custom filter functions with adapter-specific implementations for business logic.

Quick Example

import { inMemoryFilter } from "@filter-def/in-memory";

interface User {
    name: string;
    email: string;
    age: number;
}

const userFilter = inMemoryFilter<User>().def({
    name: { kind: "eq" },
    emailContains: { kind: "contains", field: "email" },
    minAge: { kind: "gte", field: "age" },
});

const users: User[] = [
    { name: "Alice", email: "[email protected]", age: 30 },
    { name: "Bob", email: "[email protected]", age: 25 },
];

const results = users.filter(
    userFilter({
        name: "Alice",
        minAge: 18,
    })
);
// Results: [{ name: "Alice", email: "[email protected]", age: 30 }]

Get Started

Installation

Install filter-def packages for your backend

Quickstart

Get up and running in 5 minutes

Core Concepts

Learn about filter definitions and types

API Reference

Explore the complete API documentation

Adapters

Choose the adapter that fits your data backend:

In-Memory

Filter JavaScript arrays with native methods

Drizzle ORM

Generate SQL WHERE clauses for Drizzle

BigQuery

Create parameterized SQL for BigQuery

Build docs developers (and LLMs) love