# pg-filters

> Easily filter any list of data with ready to use functions.

Latest version **1.1.0** (published 2023-07-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install pg-filters
pnpm add pg-filters
yarn add pg-filters
bun add pg-filters
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-07-20 |
| First published | 2022-11-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 42 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Philippe Gerbeau |
| Maintainers | philgerb93 |

## Links

- npm: https://www.npmjs.com/package/pg-filters
- Repository: https://github.com/Philgerb93/pg-filters
- Homepage: https://github.com/Philgerb93/pg-filters#readme
- Issues: https://github.com/Philgerb93/pg-filters/issues
- npm.io page: https://npm.io/package/pg-filters

## Dependencies (1)

- [dayjs](https://npm.io/package/dayjs.md) ^1.11.6

## Recent versions

- 1.1.0 (latest) — 2023-07-20
- 1.0.5 — 2023-02-02
- 1.0.4 — 2023-02-02
- 1.0.3 — 2023-02-02
- 1.0.2 — 2023-02-02
- 1.0.1 — 2022-11-14
- 1.0.0 — 2022-11-12

## README

# pg-filters

## Functions

### searchData

Filters data by using a single search string and matching its value with all the filters. Only uses `Text`and `Number` filters.

| Parameter  | Type | Usage
| ------------- | ------------- | ------------- |
| **data**  | `any[]`   | List of objects that need to be filtered.
| **filters**  | `Filter[]`  | List of filters that will be used to filter data.
| **search**  | `string`  | What the user entered in the search box.

### filterData

Filters data by using the filters.

| Parameter  | Type | Usage
| ------------- | ------------- | ------------- |
| **data**  | `any[]`   | List of objects that need to be filtered.
| **filters**  | `Filter[]`  | List of filters that will be used to filter data.

### getActiveFilters

Returns all the filters that have a value.

| Parameter  | Type | Usage
| ------------- | ------------- | ------------- |
| **filters**  | `Filter[]`  | Filters to be evaluated.

### resetFilters

Resets the value of the filters to their original state.

| Parameter  | Type | Usage
| ------------- | ------------- | ------------- |
| **filters**  | `Filter[]`  | Filters to be reset.

### restoreFiltersFromStorage

Restores filters from a JSON storage, converting each field to its original state.

| Parameter  | Type | Usage
| ------------- | ------------- | ------------- |
| **storage**  | `string`  | JSON storage.

## Filter Object

| Field  | Usage | Required
| ------------- | ------------- | ------------- |
| **field**  | Must match the field name inside the filtered object.   | &check;
| **label**  | Used to show the filter's name to the user.  |
| **inputType**  | Specifies the type of input that the user will interact with. Available types are `Text`, `Number`, `Dropdown`, `MultiSelect`, `Calendar`, `CalendarRange` and `Checkbox` | &check;
| **filterType**  | Specifies the method that will be used to filter. |
| **value**  | Used to compare values with the filtered object. User input goes there.  |
| **options**  | Used to populate a filter with options. Should only be used with `Dropdown` and `MultiSelect`.  |
| **empty**  | Sets the empty value to be matched with when filtering using `Dropdown` and `MultiSelect`.  |
| **category**  | Used to group fields together in a form.  |

## Filter Types

| Input Type  | Associated Filter Types | Default
| ------------- | ------------- | ------------- |
| `Number`, `Calendar`  | `Less`, `LessOrEqual`, `Equal`, `GreaterOrEqual`, `Greater`.   | `Equal`
| `Checkbox`  | `True`, `False`.   | `True`

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