import { Entity } from 'megalodon' ; const filtered = ( status , filters ) : boolean => { if ( filters . length === 0 ) { return false ; } const regexp = filterRegexp ( filters ) ; return status . match ( regexp ) !== null ; } ; const filterRegexp = ( filters ) : RegExp => { return new RegExp ( filters . map ( f => { let exp = escapeRegExp ( f . phrase ) ; if ( f . whole_word ) { if ( /^[\w]/ . test ( exp ) ) { exp = `\\b${ exp }` ; } if ( /[\w]$/ . test ( exp ) ) { exp = `${ exp }\\b` ; } } return exp ; } ) . join ( '|' ) , 'i' ) ; } ; const escapeRegExp = ( str ) => str . replace ( /[.*+?^${}()|[\]\\]/g , '\\$&' ) ; export default filtered ;