Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/maxprilutskiy/filterion

🪄 A declarative JavaScript library for search params orchestration.
https://github.com/maxprilutskiy/filterion

filter javascript nodejs query-string querystring search searchparams typescript urlsearchparams

Last synced: 6 days ago
JSON representation

🪄 A declarative JavaScript library for search params orchestration.

Awesome Lists containing this project

README

        


Filterion



A zero-dependency, immutable data structure for search params management.

[![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
[![codecov](https://codecov.io/gh/maxprilutskiy/filterion/branch/main/graph/badge.svg?token=XNVEAODW13)](https://codecov.io/gh/maxprilutskiy/filterion)
[![Release](https://github.com/maxprilutskiy/filterion/actions/workflows/release.yml/badge.svg)](https://github.com/maxprilutskiy/filterion/actions/workflows/release.yml)

## 📦 Install

Install `filterion` using npm:

```
npm i filterion
```

## 🔨 Usage

Require it into any module and use natively:

```javascript
import { Filterion } from 'filterion';

const filter = new Filterion()
.add('device', 'iPhone')
.add('price', 649);

console.log(filter.getPayload());

/*
{
device: { '=': [ 'iPhone' ] },
price: { '=': [ 649 ] }
}
*/
```

Or leverage the query string API:
```javascript
import { Filterion } from 'filterion';

const newQuery = new Filterion()
.fromQueryString('device=iPhone&price=649')
.remove('price')
.add('year', 2007)
.toQueryString();

console.log(newQuery);

/*
device=iPhone&year=2007
*/

```

#### Typescript

Filterion can be used in a type-safe context:

```typescript
import { Filterion } from 'filterion';

// Good
const filterion = new Filterion<{ price: string }>()
.add('price', 649);

// Bad
const filterion = new Filterion<{ name: string }>()
.add('price', 649);

/*
error TS2345: Argument of type '"price"' is not assignable to parameter of type '"name"'.
*/

```

Inspired by [immutable.js](https://github.com/immutable-js/immutable-js), an immutable collections library for JavaScript.

## License
MIT