GitHub

tsfiltor

A composable TypeScript filter system for querying and evaluating in-memory data. Provides a structured way to build complex query conditions that can be evaluated against entities.

🎯 Composable filters Build complex conditions with simple builder functions
🔍 Rich operators Equality, comparison, string matching, regex, type checking, and more
🧩 Logical operations AND, OR, NOT with nested conditions
🚀 Array extensions Optional prototype extensions for fluent API
🔧 Extensible Register custom operators easily
📦 Type-safe Full TypeScript support

Installation

npm install tsfiltor

Universal Compatibility

This package is built with dual module support (ESM + CommonJS) for maximum compatibility:

The package automatically serves the correct format:

Browser Usage

The package works in browsers via CDN. Use esm.sh or similar CDN:

<script type="module">
  import { eq, gt, filterEntities } from 'https://esm.sh/tsfiltor@latest';
  // Use the library...
</script>

Try It Live

Edit the code below and click "Run" to see the results. The package is loaded from npm via esm.sh CDN.

Editor
Ready
Output

Available Operators

Comparison

eq(field, value) - Equality
ne(field, value) - Not equal
lt(field, value) - Less than
lte(field, value) - Less than or equal
gt(field, value) - Greater than
gte(field, value) - Greater than or equal

String Operations

contains(field, value) - String/array contains
startsWith(field, value) - String starts with
endsWith(field, value) - String ends with
matches(field, pattern) - Regex pattern match

Array Operations

anyOf(field, values[]) - Value is in array
minLength(field, n) - Minimum length
maxLength(field, n) - Maximum length

Type Checking

isRecord(field) - Is plain object/Record
matchesZodSchema(field, schema) - Matches Zod schema

Logical

and(...conditions) - All conditions must match
or(...conditions) - Any condition must match
not(condition) - Negate condition

API Reference

Core Functions

Extension Functions

License

Unlicense - This is free and unencumbered software released into the public domain.

For more information, see unlicense.org