export interface HasId { id : string ; } function parseFilter ( filter ) { const positive = [ ] ; const negative = [ ] ; for ( const segment of filter . split ( ',' ) ) { let trimmed = segment . trim ( ) ; let list = positive ; if ( trimmed . startsWith ( '!' ) ) { trimmed = trimmed . slice ( 1 ) ; list = negative ; } list . push ( new RegExp ( `^${ trimmed . split ( '*' ) . join ( '.*' ) }$` ) ) ; } return ( bundle ) => ( ! positive . length || positive . some ( ( p ) => p . test ( bundle . id ) ) ) && ( ! negative . length || ! negative . some ( ( p ) => p . test ( bundle . id ) ) ) ; } export function filterById < T extends HasId > ( filterStrings , bundles ) { const filters = filterStrings . map ( parseFilter ) ; return bundles . filter ( ( b ) => ! filters . length || filters . some ( ( f ) => f ( b ) ) ) ; }