import { parse } from 'querystring' ; import pathRegexp from 'path-to-regexp' ; import type { Route } from '@/models/connect' ; 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 isAntDesignPro = ( ) : boolean => { if ( ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site' ) { return true ; } return window . location . hostname === 'preview.pro.ant.design' ; } ; export const isAntDesignProOrDev = ( ) : boolean => { const { NODE_ENV } = process . env ; if ( NODE_ENV === 'development' ) { return true ; } return isAntDesignPro ( ) ; } ; 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 ; } ; export const getRouteAuthority = ( path , routeData ) => { let authorities ; routeData . forEach ( ( route ) => { if ( pathRegexp ( `${ route . path }/(.*)` ) . test ( `${ path }/` ) ) { if ( route . authority ) { authorities = route . authority ; } if ( route . path === path ) { authorities = route . authority || authorities ; } if ( route . routes ) { authorities = getRouteAuthority ( path , route . routes ) || authorities ; } } } ) ; return authorities ; } ;