Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/maxprilutskiy/filterion
- Owner: maxprilutskiy
- License: mit
- Created: 2019-04-22T12:38:42.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-06-16T10:50:57.000Z (5 months ago)
- Last Synced: 2024-10-15T03:21:30.365Z (about 1 month 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: 37
- 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
[![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