| layout | home | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| hero |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| features |
|
Install the package:
# Using npm
npm install @mcabreradev/filter
# Using yarn
yarn add @mcabreradev/filter
# Using pnpm
pnpm add @mcabreradev/filter::: tip Import Styles Choose between classic imports (all features) or modular imports (50-70% smaller bundle). Learn more :::
Start filtering:
// Classic import
import { filter } from '@mcabreradev/filter';
// Or modular import (recommended for production)
import { filter } from '@mcabreradev/filter/core';
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 statisticsimport { 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>;
}<script setup>
import { ref } from 'vue';
import { useFilter } from '@mcabreradev/filter';
const searchTerm = ref('');
const { filtered, isFiltering } = useFilter(users, searchTerm);
</script>⚡
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
Truly zero dependencies! Tiny 12 KB bundle. Optional Zod for validation. 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, 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
Optional 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.
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' } }
]
});MIT License - see LICENSE for details.
Copyright © 2025 Miguelangel Cabrera