From d0362e226ed5e52b5551dce60ebb6bc41a7d5d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E8=90=8C=E5=93=92=E8=B5=AB=E8=90=9D?= Date: Wed, 1 Mar 2023 10:37:58 +0800 Subject: [PATCH] :hammer: Refactor: rewrite func isUrl --- src/universal/utils/common.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/universal/utils/common.ts b/src/universal/utils/common.ts index 6604b04..bc5d00e 100644 --- a/src/universal/utils/common.ts +++ b/src/universal/utils/common.ts @@ -1,4 +1,12 @@ -export const isUrl = (url: string): boolean => (/^https?:\/\//.test(url)) +export const isUrl = (url: string): boolean => { + try { + new URL(url) + return true + } catch { + return false + } +} + export const isUrlEncode = (url: string): boolean => { url = url || '' try {