@@ -65,16 +65,21 @@ export class Context {
6565
6666 /**
6767 * Find bindings using the key pattern
68- * @param pattern Key pattern with optional `*` wildcards
68+ * @param pattern Key regexp or pattern with optional `*` wildcards
6969 */
70- find ( pattern ?: string ) : Binding [ ] {
70+ find ( pattern ?: string | RegExp ) : Binding [ ] {
7171 let bindings : Binding [ ] = [ ] ;
72- if ( pattern ) {
72+ let glob : RegExp | undefined = undefined ;
73+ if ( typeof pattern === 'string' ) {
7374 // TODO(@superkhau): swap with production grade glob to regex lib
7475 Binding . validateKey ( pattern ) ;
75- const glob = new RegExp ( '^' + pattern . split ( '*' ) . join ( '.*' ) + '$' ) ;
76+ glob = new RegExp ( '^' + pattern . split ( '*' ) . join ( '.*' ) + '$' ) ;
77+ } else if ( pattern instanceof RegExp ) {
78+ glob = pattern ;
79+ }
80+ if ( glob ) {
7681 this . registry . forEach ( binding => {
77- const isMatch = glob . test ( binding . key ) ;
82+ const isMatch = glob ! . test ( binding . key ) ;
7883 if ( isMatch ) bindings . push ( binding ) ;
7984 } ) ;
8085 } else {
@@ -87,12 +92,15 @@ export class Context {
8792
8893 /**
8994 * Find bindings using the tag pattern
90- * @param pattern Tag pattern with optional `*` wildcards
95+ * @param pattern Tag name regexp or pattern with optional `*` wildcards
9196 */
92- findByTag ( pattern : string ) : Binding [ ] {
97+ findByTag ( pattern : string | RegExp ) : Binding [ ] {
9398 const bindings : Binding [ ] = [ ] ;
9499 // TODO(@superkhau): swap with production grade glob to regex lib
95- const glob = new RegExp ( '^' + pattern . split ( '*' ) . join ( '.*' ) + '$' ) ;
100+ const glob =
101+ typeof pattern === 'string'
102+ ? new RegExp ( '^' + pattern . split ( '*' ) . join ( '.*' ) + '$' )
103+ : pattern ;
96104 this . registry . forEach ( binding => {
97105 const isMatch = Array . from ( binding . tags ) . some ( tag => glob . test ( tag ) ) ;
98106 if ( isMatch ) bindings . push ( binding ) ;
0 commit comments