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: about 1 year ago
JSON representation
🪄 A declarative JavaScript library for search params orchestration.
- Host: GitHub
- URL: https://github.com/maxprilutskiy/filterion
- Owner: maxprilutskiy
- License: mit
- Created: 2019-04-22T12:38:42.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2024-06-16T10:50:57.000Z (almost 2 years ago)
- Last Synced: 2025-03-04T22:33:56.360Z (about 1 year ago)
- Topics: filter, javascript, nodejs, query-string, querystring, search, searchparams, typescript, urlsearchparams
- Language: TypeScript
- Homepage: https://npmjs.com/package/filterion
- Size: 1.47 MB
- Stars: 38
- Watchers: 17
- Forks: 100
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README

Filterion
[](http://www.typescriptlang.org/)
[](https://codecov.io/gh/maxprilutskiy/filterion)
[](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