filterion
v1.5.3

Instalar filterion usando NPM:
npm i filterion
Requerirlo en cualquier módulo y usar de forma nativa:
import { Filterion } from 'filterion' ;
const filter = new Filterion ( )
. add ( 'device' , 'iPhone' )
. add ( 'price' , 649 ) ;
console . log ( filter . getPayload ( ) ) ;
/*
{
device: { '=': [ 'iPhone' ] },
price: { '=': [ 649 ] }
}
*/O aprovechar la API de cadena de consulta:
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
*/ La filtrión se puede usar en un contexto seguro:
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"'.
*/Inspirado en Immutable.js, una biblioteca de colecciones inmutables para JavaScript.
MIT