Skip to content

@mcabreradev/filterSQL-like Array Filtering

A powerful TypeScript/JavaScript library with MongoDB-style operators, lazy evaluation, and zero dependencies

Filter Library

Quick Start โ€‹

Install the package:

bash
npm install @mcabreradev/filter

Start filtering:

typescript
import { filter } from '@mcabreradev/filter';

const users = [
  { name: 'Alice', email: 'alice@example.com', age: 30, city: 'Berlin' },
  { name: 'Bob', email: 'bob@example.com', age: 25, city: 'London' },
  { name: 'Charlie', email: 'charlie@example.com', age: 35, city: 'Berlin' }
];

// Simple string matching
filter(users, 'Berlin');
// โ†’ Returns Alice and Charlie

// Wildcard patterns
filter(users, '%alice%');
// โ†’ Returns Alice

// Object-based filtering
filter(users, { city: 'Berlin', age: 30 });
// โ†’ Returns Alice

// MongoDB-style operators
filter(users, { age: { $gte: 25, $lt: 35 } });
// โ†’ Returns Bob and Alice

// Logical operators
filter(users, {
  $and: [
    { city: 'Berlin' },
    { age: { $gte: 30 } }
  ]
});
// โ†’ Returns Alice and Charlie

// Debug mode for visual inspection
import { filterDebug } from '@mcabreradev/filter';

const result = filterDebug(users, {
  $and: [
    { city: 'Berlin' },
    { $or: [{ age: { $lt: 30 } }, { premium: true }] }
  ]
});

result.print();
// Outputs visual tree with match statistics

Framework Integration โ€‹

React โ€‹

typescript
import { useFilter, useDebouncedFilter } from '@mcabreradev/filter';

function UserList() {
  const { filtered, isFiltering } = useFilter(users, { active: true });
  return <div>{filtered.map(user => <User key={user.id} {...user} />)}</div>;
}

Vue โ€‹

vue
<script setup>
import { ref } from 'vue';
import { useFilter } from '@mcabreradev/filter';

const searchTerm = ref('');
const { filtered, isFiltering } = useFilter(users, searchTerm);
</script>

Svelte โ€‹

svelte
<script>
import { writable } from 'svelte/store';
import { useFilter } from '@mcabreradev/filter';

const searchTerm = writable('');
const { filtered, isFiltering } = useFilter(users, searchTerm);
</script>

Why Choose This Library? โ€‹

โšก
Blazing Fast
530x faster with caching, 500x faster with lazy evaluation. Optimized for production workloads.
๐ŸŽฏ
Developer Friendly
Intuitive API that feels natural. SQL-like syntax you already know. Full TypeScript support.
๐Ÿ”ง
Flexible
Multiple filtering strategies. Use what fits your use case. Combine approaches seamlessly.
๐Ÿ“ฆ
Production Ready
Battle-tested with 300+ tests. Used in production by companies worldwide. MIT licensed.
๐Ÿชถ
Ultra Lightweight
Zero dependencies (except Zod). Tiny bundle size. No bloat, just pure filtering power.
๐Ÿ”’
Type-Safe by Default
Built with strict TypeScript. Catch errors at compile time. Full IntelliSense and autocomplete support.
๐ŸŽจ
Framework Agnostic
Works everywhere: React, Vue, Svelte, Angular, Node.js, Deno, Bun. First-class hooks and composables included.
๐Ÿ“Š
Handles Big Data
Process millions of records efficiently. Lazy evaluation for memory optimization. Built for scale.
๐Ÿ›ก๏ธ
Runtime Validation
Zod-powered schema validation. Catch invalid queries before they run. Safe and predictable behavior.
๐ŸŽ“
Easy Learning Curve
Familiar MongoDB and SQL patterns. Comprehensive docs with 150+ examples. Get productive in minutes.
๐Ÿ”„
Active Maintenance
Regular updates and improvements. Responsive to issues and feature requests. Community-driven development.
๐ŸŒ
Edge-Ready
Works in Cloudflare Workers, Vercel Edge, Deno Deploy. Perfect for serverless and edge computing.
๐Ÿงช
Test Coverage
100% code coverage. 300+ unit and integration tests. Type-level tests for TypeScript guarantees.
๐ŸŽญ
No Vendor Lock-in
Pure JavaScript/TypeScript. No proprietary formats. Easy to migrate to or from. You own your data.
โš™๏ธ
Highly Configurable
Customize behavior to your needs. Configure depth, caching, case sensitivity. Fine-tune performance.

Real-World Example โ€‹

typescript
interface Product {
  id: number;
  name: string;
  price: number;
  category: string;
  rating: number;
  inStock: boolean;
  tags: string[];
}

const products: Product[] = [...];

// E-commerce: Find affordable, highly-rated electronics in stock
const affordableElectronics = filter(products, {
  category: 'Electronics',
  price: { $lte: 1000 },
  rating: { $gte: 4.5 },
  inStock: { $eq: true }
});

// Search: Products matching keyword with filters
const searchResults = filter(products, {
  name: { $contains: 'laptop' },
  brand: { $in: ['Apple', 'Dell', 'HP'] },
  price: { $gte: 500, $lte: 2000 }
});

// Complex queries with logical operators
const premiumDeals = filter(products, {
  $and: [
    { inStock: true },
    {
      $or: [
        { rating: { $gte: 4.5 } },
        { price: { $lt: 50 } }
      ]
    },
    { $not: { category: 'Clearance' } }
  ]
});

Community & Support โ€‹

License โ€‹

MIT License - see LICENSE for details.

Copyright ยฉ 2025 Miguelangel Cabrera

Released under the MIT License.