| | |
| | | /** |
| | | * 路径匹配器 |
| | | * @param {string} pattern |
| | | * @param {string} path |
| | | * @returns {Boolean} |
| | | */ |
| | | export function isPathMatch(pattern: string, path: string) { |
| | | const regexPattern = pattern |
| | | .replace(/\//g, '\\/') |
| | | .replace(/\*\*/g, '__DOUBLE_STAR__') |
| | | .replace(/\*/g, '[^\\/]*') |
| | | .replace(/__DOUBLE_STAR__/g, '.*'); |
| | | const regex = new RegExp(`^${regexPattern}$`); |
| | | return regex.test(path); |
| | | } |
| | | |
| | | /** |
| | | * 判断url是否是http或https |
| | | * @returns {Boolean} |
| | | * @param url |
| | |
| | | */ |
| | | export const validEmail = (email: string) => { |
| | | const reg = |
| | | /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; |
| | | /^(([^<>()\]\\.,;:\s@"]+(\.[^<>()\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; |
| | | return reg.test(email); |
| | | }; |
| | | |