# @loopback/filter

> Utility typings and filters for LoopBack filters.

Latest version **6.0.15** (published 2026-08-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @loopback/filter
pnpm add @loopback/filter
yarn add @loopback/filter
bun add @loopback/filter
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 6.0.15 |
| Published | 2026-08-18 |
| First published | 2020-09-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | 20 \|\| 22 \|\| 24 |
| Dependencies | 1 |
| Unpacked size | 58.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5106 |
| Author | IBM Corp. and LoopBack contributors |
| Maintainers | rfeng, rmg, dhmlau, theprez, frbuceta, marioestradarosa, achrinza |

## Links

- npm: https://www.npmjs.com/package/@loopback/filter
- Repository: https://github.com/loopbackio/loopback-next
- Homepage: https://github.com/loopbackio/loopback-next#readme
- Issues: https://github.com/loopbackio/loopback-next/issues
- npm.io page: https://npm.io/package/@loopback/filter

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.8.1

## Recent versions

- 6.0.15 (latest) — 2026-08-18
- 6.0.14 — 2026-07-16
- 6.0.13 — 2026-06-11
- 6.0.12 — 2026-05-12
- 6.0.11 — 2026-04-14
- 6.0.10 — 2026-03-11
- 6.0.9 — 2026-02-10
- 6.0.8 — 2026-01-12
- 6.0.7 — 2025-12-09
- 6.0.6 — 2025-11-11
- 6.0.5 — 2025-10-15
- 6.0.4 — 2025-09-10
- 6.0.3 — 2025-08-11
- 6.0.2 — 2025-07-15
- 6.0.1 — 2025-06-12
- … 53 more at https://npm.io/package/@loopback/filter/versions

## README

# @loopback/filter

A set of utility typings and filter builders to aid in constructing LoopBack
filters using the
[builder pattern](https://en.wikipedia.org/wiki/Builder_pattern).

## Overview

This lightweight module provides strongly-typed typings and filter builders to
intuitively construct LoopBack filters to be used against querying a LoopBack
filter-compatible server over the network or within the server itself.

## Installation

{% include note.html content="Already installed `@loopback/repository`? Import from there instead. This package is meant for standalone use without `@loopback/repository`." %}

```sh
npm install --save @loopback/filter
```

## Basic use

### WhereBuilder

The `WhereBuilder` is a builder specifically meant to construct the `where`
portion of the filter.

```ts
import {WhereBuilder} from '@loopback/filter';

const whereBuilder = new WhereBuilder();
const where = whereBuilder
  .between('price', 99, 299)
  .and({brand: 'LoopBack'}, {discount: {lt: 20}})
  .or({instock: true})
  .build();
```

### FilterBuilder

The `FilterBuilder` is a builder to construct the filter as a whole.

```ts
import {FilterBuilder} from '@loopback/filter';

const filterBuilder = new FilterBuilder();
const filter = filterBuilder
  .fields('id', 'a', 'b')
  .limit(10)
  .offset(0)
  .order(['a ASC', 'b DESC'])
  .where({id: 1})
  .build();
```

`FilterBuilder.where()` also accepts an instance of `WhereBuilder`.

```ts
const filterBuilder = new FilterBuilder();
const filter = filterBuilder
  // ...
  .where(where)
  .build();
```

## Advanced use

### Strong typings

The `FilterBuilder` and `WhereBuilder` accept a model or any string-based key
objects' typing for strong typings:

```ts
/**
 * Everything was imported from `@loopback/repository` as `@loopback/filter`
 * is re-exported in that package.
 **/
import {
  FilterBuilder,
  model,
  property,
  WhereBuilder,
} from '@loopback/repository';

@model()
class Todo extends Entity {
  @property({id: true})
  id: number;

  @property()
  title: string;

  @property()
  description: string;

  @property()
  priority: number;
}

const whereBuilder = new WhereBuilder<Todo>();
const where = whereBuilder.between('priority', 1, 3).build();

const filterBuilder = new FilterBuilder<Todo>();
const filter = filterBuilder
  .fields('id', 'title')
  .order(['title DESC'])
  .where(where)
  .build();
```

## API docs

See the API docs for
[FilterBuilder](https://loopback.io/doc/en/lb4/apidocs.filter.filterbuilder.html)
and
[WhereBuilder](https://loopback.io/doc/en/lb4/apidocs.filter.wherebuilder.html)
for more details on the full API.

## Contributions

- [Guidelines](https://github.com/loopbackio/loopback-next/blob/master/docs/CONTRIBUTING.md)
- [Join the team](https://github.com/loopbackio/loopback-next/issues/110)

## Tests

Run `npm test` from the root folder.

## Contributors

See
[all contributors](https://github.com/loopbackio/loopback-next/graphs/contributors).

## License

MIT

---
_Source: https://npm.io/package/@loopback/filter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
