
Company News
Meet the Socket Team at RSAC and BSidesSF 2026
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.
filter-utils
Advanced tools
[](https://github.com/hvpaiva/filter-utils/actions?query=workflow%3ARelease) [;
This will create a filter object that when passed to Repository will fetch a list with a limit of 10 results, without skipping any value and sort by 'createdAt' attribute in ascending direction.
| Attribute | Type | Description |
|---|---|---|
| limit | Positive Integer | The number of values fetched by the query. Ex.: The number 10 will bring the first 10 values. |
| offset | Positive Integer | The number of values skipped in the query. Ex.: The value 5, will ignore the first 5 values. |
| order | String | The order String. Composed by the prefix (+ or -) an the attribute. |
| model | Class Instance | The Object with values to be filtered. |
As you always filter some kind of entity, you can create an instance of that entity to help to filter by some value:
const person = new Person({ name: 'John' });
const filter = new Filter<Person>({
model: person
});
This will create a filter object that will fetch all Persons named 'John'.
It's not required to pass the Person in Filter generics (
new Filter<Person>()), but is useful for type checking.
To create an order, you'll need to pass an prefix (+ or -) and some attribute of the filtered Model.
const filter = new Filter<Person>({
order: '-name'
});
It'll filter sorting by name in descending direction.
After constructing the Filter object. You can use it with the responsible to fetch the data.
In this lib, we only created this for MongoRepository of the TypeOrm:
import { Filter } from 'filter-utils';
import { MongoRepository } from 'typeorm';
const filter = new Filter<Person>({ order: 'createdAt' });
const persons = new MongoRepository<Person>().find({
...filter.getTypeOrmMongoFilter()
});
Using with MongoRepository of the TypeORM lib, it will format the filter object that way the repository needed.
You can also use other objects to create your specific use case:
This will create by the string order an Order Type, which is a object with the attribute and it's order direction (ASC or DESC).
import { OrderBuilder } from 'filter-utils';
const nameOrder = OrderBuilder<Person>('-name');
// { name: 'DESC' } -> Order instance
const createdAtOrder = OrderBuilder<Person>('+createdAt');
// { createdAt: 'ASC' } -> Order instance
The Query object is used in Filter to compose the most common query attributes:
take works as Filter's limit, skip works as Filter's offset and order is the same.
The order is passed in String format, but in Query instance it'll be converted to Order type.
import { Query } from 'filter-utils';
const query = new Query<Person>({
take: 10,
skip: 10,
order: '+createdAt'
});
// {
// take: 10,
// skip: 10,
// order: { createdAt: 'ASC' }
// } -> Query instance
Bug reports and pull requests are welcome on GitHub
The project is available as open source under the terms of the MIT License.
FAQs
[](https://github.com/hvpaiva/filter-utils/actions?query=workflow%3ARelease) [
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Join Socket for live demos, rooftop happy hours, and one-on-one meetings during BSidesSF and RSA 2026 in San Francisco.

Research
/Security News
Malicious Packagist packages disguised as Laravel utilities install an encrypted PHP RAT via Composer dependencies, enabling remote access and C2 callbacks.

Research
/Security News
OpenVSX releases of Aqua Trivy 1.8.12 and 1.8.13 contained injected natural-language prompts that abuse local AI coding agents for system inspection and potential data exfiltration.