const countStars = ( input ) => { try { return input . match ( /\*\*/g ) . length ; } catch ( error ) { return 0 ; } } ; export const convertToPattern = ( url ) : string => { const regexp = url [ 0 ] === '/' ? url . substring ( 1 ) : url ; if ( url . endsWith ( '/*' ) && countStars ( url ) === 0 ) { return `^/?${ regexp . replace ( /\/\*/g , '($|/$|/[^/]*$)' ) }$` ; } if ( url . endsWith ( '/**' ) && countStars ( url ) === 1 ) { return `^/?${ regexp . replace ( /\/\*\*/g , '($|/.*$)' ) }$` ; } if ( countStars ( url ) === 0 ) { return `^/?${ url }$` ; } return convertToPattern ( regexp . replace ( '**' , '[^/]*' ) ) ; } ; const urlGlob = ( pattern , input ) : boolean => { const re = new RegExp ( convertToPattern ( pattern ) ) ; return re . test ( input ) ; } ; export default urlGlob ;