text: /*
   * Copyright 2020. the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  import {parse} from 'querystring'
  import pathRegexp from 'path-to-regexp'
  
  /* eslint no-useless-escape:0 import/prefer-default-export:0 */
  const reg = /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/
  export const isUrl = path => reg.test(path)
  export const isAntDesignPro = () => {
    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 = () => {
    const {NODE_ENV} = process.env
  
    if (NODE_ENV === 'development') {
      return true
    }
  
    return isAntDesignPro()
  }
  export const getPageQuery = () => parse(window.location.href.split('?')[1])
  /**
   * props.route.routes
   * @param router [{}]
   * @param pathname string
   */
  
  export const getAuthorityFromRouter = (router = [], pathname) => {
    const authority = router.find(
      ({routes, path = '/'}) =>
        (path && pathRegexp(path).exec(pathname)) ||
        (routes && getAuthorityFromRouter(routes, pathname)),
    )
    if (authority) return authority
    return undefined
  }
  export const getRouteAuthority = (path, routeData) => {
    let authorities
    routeData.forEach(route => {
      // match prefix
      if (pathRegexp(`${route.path}/(.*)`).test(`${path}/`)) {
        if (route.authority) {
          authorities = route.authority
        } // exact match
  
        if (route.path === path) {
          authorities = route.authority || authorities
        } // get children authority recursively
  
        if (route.routes) {
          authorities = getRouteAuthority(path, route.routes) || authorities
        }
      }
    })
    return authorities
  }
  