Skip to content

Commit

Permalink
fix: 修复isUrl判断错误bug #526
Browse files Browse the repository at this point in the history
  • Loading branch information
clddup committed Sep 2, 2024
1 parent 0e99f83 commit 3cd89bd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utils/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ export const isServer = typeof window === 'undefined'
export const isClient = !isServer

export const isUrl = (path: string): boolean => {
const reg =
/(((^https?:(?:\/\/)?)(?:[-:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&%@.\w_]*)#?(?:[\w]*))?)$/
return reg.test(path)
try {
new URL(path)
return true
} catch (_error) {
return false
}
}

export const isDark = (): boolean => {
Expand Down

0 comments on commit 3cd89bd

Please sign in to comment.