File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -491,6 +491,30 @@ export abstract class StreamExpressionEngine {
491491 return streams . filter ( ( stream ) => stream . library ) ;
492492 } ;
493493
494+ this . parser . functions . message = function (
495+ streams : ParsedStream [ ] ,
496+ mode : 'exact' | 'includes' ,
497+ ...messages : string [ ]
498+ ) {
499+ if ( ! Array . isArray ( streams ) || streams . some ( ( stream ) => ! stream . type ) ) {
500+ throw new Error ( 'Your streams input must be an array of streams' ) ;
501+ } else if (
502+ messages . length === 0 ||
503+ messages . some ( ( m ) => typeof m !== 'string' )
504+ ) {
505+ throw new Error (
506+ 'You must provide one or more message string parameters'
507+ ) ;
508+ } else if ( mode !== 'exact' && mode !== 'includes' ) {
509+ throw new Error ( "Mode must be either 'exact' or 'includes'" ) ;
510+ }
511+ return streams . filter ( ( stream ) => {
512+ mode == 'exact'
513+ ? messages . includes ( stream . message || '' )
514+ : messages . some ( ( m ) => ( stream . message || '' ) . includes ( m ) ) ;
515+ } ) ;
516+ } ;
517+
494518 this . parser . functions . count = function ( streams : ParsedStream [ ] ) {
495519 if ( ! Array . isArray ( streams ) ) {
496520 throw new Error (
You can’t perform that action at this time.
0 commit comments