src/utils/validate.ts
@@ -1,4 +1,20 @@ /** * 路径匹配器 * @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