This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
@mcabreradev/filter is a TypeScript-first filtering engine for arrays with SQL-like wildcards, MongoDB-style operators, lazy evaluation, memoization, and framework integrations (React, Vue, Angular, Preact, SolidJS). It provides 18+ operators for advanced filtering with zero dependencies (except Zod for validation).
# Install dependencies
pnpm install
# Build project (outputs to build/)
pnpm build
# Type checking
pnpm typecheck# Run all unit tests
pnpm test
# Run tests in watch mode
pnpm test:watch
# Run tests with UI
pnpm test:ui
# Generate coverage report
pnpm test:coverage
# Run TypeScript type tests (tsd)
pnpm test:types
# Run all checks (lint, typecheck, type tests, test, docs tests)
pnpm run check
# Run docs tests only
pnpm run test:docs# Lint code
pnpm lint
# Fix linting issues
pnpm lint:fix
# Format code with Prettier
pnpm format# Publish major version (runs check, version bump, publish)
pnpm run publish:major
# Publish minor version
pnpm run publish:minor
# Publish patch version
pnpm run publish:patch
# Release (push tags to remote)
pnpm run release
# Full release workflow (publish + push tags)
pnpm run release:major
pnpm run release:minor
pnpm run release:patch# Start docs dev server (http://localhost:5173/)
pnpm run docs:dev
# Build documentation
pnpm run docs:build
# Preview built docs
pnpm run docs:preview
# Generate API documentation
pnpm run docs:apisrc/index.ts- Main entry point that re-exports all public APIssrc/core/- Core filtering logicfilter/filter.ts- Main filter function with caching and debug supportlazy/filter-lazy.ts- Lazy evaluation with generators for large datasets
src/operators/- MongoDB-style operator implementationscomparison/- $gt, $gte, $lt, $lte, $eq, $nearray/- $in, $nin, $contains, $sizestring/- $startsWith, $endsWith, $contains, $regex, $matchlogical/- $and, $or, $notdatetime/- Date/time comparison operatorsgeospatial/- Geospatial distance operatorsoperator-processor.ts- Processes operator-based expressions
src/predicate/- Predicate function buildersfactory/predicate-factory.ts- Creates appropriate predicate based on expression type- Handles string wildcards (%, _), negation (!), object-based, and function predicates
src/comparison/- Deep comparison logic (each in a subdirectory)deep/- Recursive deep equality for nested objectsobject/- Object comparison with maxDepth supportproperty/- Property-level comparison with wildcards
src/config/- Configuration managementdefault-config.ts- Default configuration valuesconfig-builder.ts- Merges user options with defaults
src/validation/- Runtime validation with Zodsrc/debug/- Debug mode with tree visualizationdebug-filter.ts,debug-tree-builder.ts,debug-formatter.ts,debug-evaluator.ts
src/errors/- Custom error types and helperssrc/constants/- Shared constants (filter.constants.ts)src/utils/- Utility functions (each in a subdirectory)cache/- Result caching with WeakMapmemoization/- Predicate and regex memoizationlazy-iterators/- Generator utilities (take, skip, map, etc.)pattern-matching/- SQL wildcard matching (%, _)type-guards/- TypeScript type guardsoperator-detection/- Detects operator-based expressionssort/,date-time/,geo-distance/,typed-filter/,performance-monitor/
src/integrations/- Framework integrations (all optional peer deps)react/- React hooks (useFilter, useDebouncedFilter, useFilteredState, usePaginatedFilter)vue/- Vue composables with reactivityangular/- Angular integrationpreact/- Preact hookssolidjs/- SolidJS integrationshared/- Shared utilities (debounce, pagination)
src/types/- TypeScript type definitions
Predicate Factory Pattern: The predicate-factory.ts determines the appropriate predicate builder based on expression type (string, object, function, or primitive).
Operator Processing: Operators are processed in operator-processor.ts, which detects operator-based expressions and delegates to specific operator implementations.
Multi-Layer Caching: Three-tier caching strategy:
- Result cache - Complete filter results (WeakMap-based)
- Predicate cache - Compiled predicate functions
- Regex cache - Compiled regex patterns
Lazy Evaluation: Generator-based filtering in src/core/lazy/filter-lazy.ts enables early exit and memory-efficient processing of large datasets.
Debug Tree: Debug mode builds an expression tree showing condition evaluations, match counts, and execution timings.
src/**/*.test.ts- Unit tests co-located with source files__test__/filter.test.ts- Integration tests for main filter function__test__/test-d/- TypeScript type tests using tsd__test__/memoization-integration.test.ts- Caching integration tests
Tests use Vitest and must achieve comprehensive coverage.
Runs automatically on commit:
- lint-staged (eslint + prettier on staged files)
- Type checking
Runs automatically on push:
- All unit tests
- Type tests (tsd)
- Type checking
- Linting all files
- Full check command
- Main branch:
main - Feature branches: Use prefixes
feat/,fix/,docs/,refactor/,test/,chore/
- All source code must be TypeScript (no
.jsinsrc/) - Strict mode enabled - all compiler options are strict
- Target: ES2022 with ESM modules
- Tests excluded from build output
- Functional programming preferred - pure functions, avoid side effects
- Modular design - small, focused modules with single responsibility
- Export from
index.tsbarrels for clean imports - Dont add jsdoc and comments
To add new operators:
- Create implementation in appropriate
src/operators/*.operators.tsfile - Add type definitions to
src/types/operators.types.ts - Update operator detection in
src/utils/operator-detection/ - Add comprehensive tests
- All config options defined in
src/config/default-config.ts - Options: caseSensitive, maxDepth, enableCache, debug, verbose, showTimings, colorize, customComparator
- Merge user options via
mergeConfig()inconfig-builder.ts
Framework-specific code lives in src/integrations/<framework>/:
- React uses hooks pattern
- Vue uses Composition API
- Angular, Preact, SolidJS also supported
- Shared utilities in
src/integrations/shared/ - All optional peer dependencies
The project uses semantic versioning:
- Run
pnpm run publish:[major|minor|patch]- runs all checks, bumps version, publishes to npm - Run
pnpm run releaseto push git tags - Or use combined commands:
pnpm run release:[major|minor|patch]
Pre-publish checks ensure:
- All tests pass
- Type tests pass
- Type checking succeeds
- Linting passes
- No uncommitted changes
package.json- Main:build/index.js, Types:build/index.d.tstsconfig.json- TypeScript config with strict mode.husky/- Git hooks configurationdocs/- VitePress documentation siteexamples/- Usage examples referenced in docs