import { parse } from 'querystring' ; import pathRegexp from 'path-to-regexp' ; const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/ ; export const isUrl = ( path ) : boolean => reg . test ( path ) ; export const openWindow = ( url ) : boolean => { const otherWindow = window . open ( ) ; if ( otherWindow != null ) { otherWindow . opener = null ; otherWindow . location . href = url ; } return false ; } ; export const stopPropagation = ( e ) => { e . stopPropagation ( ) ; if ( e . nativeEvent . stopImmediatePropagation ) { e . nativeEvent . stopImmediatePropagation ( ) ; } } ; export const getPageQuery = ( ) => parse ( window . location . href . split ( '?' ) [ 1 ] ) ; param router param pathname export const getAuthorityFromRouter = < T extends { path : string ; } > ( router = [ ] , pathname ) : T | undefined => { const authority = router . find ( ( { path } ) => path && pathRegexp ( path ) . exec ( pathname ) ) ; if ( authority ) return authority ; return undefined ; } ;