filterion
v1.5.3

NPMを使用してfilterionをインストールします。
npm i filterion
任意のモジュールに要求し、ネイティブに使用します。
import { Filterion } from 'filterion' ;
const filter = new Filterion ( )
. add ( 'device' , 'iPhone' )
. add ( 'price' , 649 ) ;
console . log ( filter . getPayload ( ) ) ;
/*
{
device: { '=': [ 'iPhone' ] },
price: { '=': [ 649 ] }
}
*/または、クエリ文字列APIを活用してください。
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
*/ フィルタリオンは、タイプセーフコンテキストで使用できます。
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"'.
*/JavaScript用のImmutable Collections LibraryであるImmutable.jsに触発されました。
mit