utils.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. /* eslint no-useless-escape:0 import/prefer-default-export:0 */
  2. const reg =
  3. /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/
  4. export const isUrl = (path: string): boolean => reg.test(path)
  5. export const isAntDesignPro = (): boolean => {
  6. if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site') {
  7. return true
  8. }
  9. return window.location.hostname === 'preview.pro.ant.design'
  10. }
  11. // 给官方演示站点用,用于关闭真实开发环境不需要使用的特性
  12. export const isAntDesignProOrDev = (): boolean => {
  13. const { NODE_ENV } = process.env
  14. if (NODE_ENV === 'development') {
  15. return true
  16. }
  17. return isAntDesignPro()
  18. }
  19. export const formatPermission = (values: any) => {
  20. const newValues = { ...values }
  21. // eslint-disable-next-line no-restricted-syntax
  22. for (const key in newValues) {
  23. if (Object.prototype.hasOwnProperty.call(values, key)) {
  24. if (key.indexOf('show') !== -1) {
  25. delete newValues[key]
  26. }
  27. }
  28. }
  29. return newValues
  30. }