Skip to content

Getting Started โ€‹

Welcome to @mcabreradev/filter - a powerful, SQL-like array filtering library for TypeScript and JavaScript with advanced pattern matching, MongoDB-style operators, deep object comparison, and zero dependencies.

What is @mcabreradev/filter? โ€‹

Go beyond JavaScript's native Array.filter() with a library that understands your data:

  • ๐ŸŽฏ SQL-like Wildcards - Use % and _ for flexible pattern matching
  • ๐Ÿ” Deep Object Filtering - Search through nested objects up to configurable depths
  • โšก Zero Dependencies - Lightweight and production-ready (only Zod for runtime validation)
  • ๐Ÿ”’ Type-Safe - Built with strict TypeScript for maximum reliability
  • ๐ŸŽจ Multiple Strategies - String patterns, objects, predicates, operators, or custom comparators
  • ๐Ÿš€ Performance Optimized - Optional caching and regex compilation optimization
  • ๐Ÿ“ฆ MongoDB-Style Operators - 18 operators for advanced filtering (v5.0.0+)
  • ๐Ÿ’จ Lazy Evaluation - Process large datasets efficiently with generators (v5.1.0+)
  • ๐Ÿงช Battle-Tested - 300+ tests ensuring reliability

Why Choose This Library? โ€‹

Developer Experience โ€‹

The API is designed to be intuitive and familiar. If you know SQL wildcards or MongoDB queries, you already know how to use this library.

typescript
// Familiar SQL-like syntax
filter(users, '%@example.com%');

// MongoDB-style operators
filter(products, { price: { $gte: 100, $lte: 500 } });

// Simple object matching
filter(items, { category: 'Electronics', inStock: true });

Performance โ€‹

Built for production with multiple optimization strategies:

  • 530x faster with result caching
  • 500x faster with lazy evaluation for early exits
  • Regex pattern caching for repeated queries
  • Predicate memoization across different arrays

Type Safety โ€‹

Full TypeScript support with strict typing:

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

const users: User[] = [...];
const result = filter<User>(users, { age: { $gte: 18 } });
// result is User[] with full type inference

Framework Integration โ€‹

First-class support for modern frameworks:

  • React Hooks - useFilter, useDebouncedFilter, usePaginatedFilter
  • Vue Composables - Full Composition API support with reactivity
  • Svelte Stores - Reactive store-based filtering

Browser Support โ€‹

Works in all modern browsers and Node.js:

  • Node.js: >= 20
  • Browsers: Chrome, Firefox, Safari, Edge (latest versions)
  • TypeScript: >= 5.0
  • Module Systems: ESM, CommonJS

Next Steps โ€‹

Community & Support โ€‹

Released under the MIT License.