filtrix
v0.1.0
Published
Flexible filtering and sorting for structured data arrays.
Maintainers
Readme
filtrix
filtrix is a flexible, configuration-based utility for filtering and sorting arrays of objects.
Ideal for building frontend table filters, search results, and consistent UI logic across large apps.
Features
- 🔍 Full-text search over multiple fields
- 🧩 Configurable filter operators (
equals,includes,startsWith, etc.) - 🧠 Custom filters and sorts per field
- 🔃 Declarative sorting with direction
- 📦 Small footprint and framework-agnostic
Usage
import { filterAndSort } from 'filtrix';
const config = {
filtersConfig: {
status: {
field: 'status',
operator: 'equals',
type: 'string',
},
amount: {
field: 'price',
operator: 'greaterThan',
type: 'number',
},
},
sortingConfig: {
price: {
field: 'price',
type: 'number',
},
},
searchIndexes: ['title', 'description'],
};
const filters = {
status: 'active',
amount: 100,
search: 'shoes',
sorting: 'price',
sortingDirection: 'descending',
};
const result = filterAndSort(config, filters, items);Configuration
filtersConfig
Each key maps to a field with:
| Option | Type | Description |
|----------------|------------|--------------------------------------------------|
| field | string | Path to field in item |
| operator | string | One of equals, includes, gt, etc. |
| type | string | Optional: string, number, date, etc. |
| caseSensitive| boolean | Optional, only for string comparisons |
| customFilter | Function | (itemValue, filterValue) => boolean |
sortingConfig
Each key maps to sorting behavior:
| Option | Type | Description |
|---------------|------------|----------------------------------------------|
| field | string | Path to field |
| type | string | Optional: string, number, date, etc. |
| direction | string | Optional default: ascending / descending |
| customSort | Function | Optional custom comparator |
searchIndexes
Array of paths to search by full-text search via filters.search.
License
MIT
