import axios from 'axios' import { EMAIL_REG, PASSWORD_REG, PHONE_REG, TCP_URL_REG, URL_REG } from '../constants' const isResError = axios.isAxiosError const isURL = (url: string) => URL_REG.test(url) const isTcpURL = (url: string) => TCP_URL_REG.test(url) const isEmail = (email: string) => EMAIL_REG.test(email) const isPhone = (phone: string) => PHONE_REG.test(phone) const isPassword = (password: string) => PASSWORD_REG.test(password) const isFilePath = (path: string) => { try { // 没有使用正则判断,因为还需要多判断一次是否是 URL const urlObject = new URL(path) return urlObject.protocol === 'file:' } catch (error) { // URL 构造函数会在接收到无效 URL 时抛出错误 return false } } export { isResError, isURL, isTcpURL, isEmail, isPhone, isPassword, isFilePath }