feat: 优化路径工具函数
All checks were successful
Egg Server MIflow / build-image (push) Successful in 36s

This commit is contained in:
zhaoyingbo 2024-07-30 09:37:34 +00:00
parent 6ac6bfd8ab
commit c4c10f2ba0

View File

@ -8,12 +8,10 @@ export const safeJsonStringify = (obj: any) => {
export const makeCheckPathTool = (url: string, prefix?: string) => {
const { pathname } = new URL(url)
const prefixPath = prefix ? `${prefix}/` : ""
return {
// 精确匹配
exactPath: (path: string) => pathname === `${prefixPath}${path}`,
exactCheck: (path: string) => pathname === `${prefix}${path}`,
// 前缀匹配
startsWithPath: (path: string) =>
pathname.startsWith(`${prefixPath}${path}`),
startsWithCheck: (path: string) => pathname.startsWith(`${prefix}${path}`),
}
}