Skip to content

Commit 9278cc0

Browse files
committed
refactor: checkHttpUrl logic
1 parent 94b9e32 commit 9278cc0

1 file changed

Lines changed: 2 additions & 7 deletions

File tree

  • package/validationUtil/checkHttpUrl

package/validationUtil/checkHttpUrl/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
export default function checkHttpUrl(str: string): boolean {
2-
const roughPattern = /^(https?:\/\/)/i;
3-
4-
if (!roughPattern.test(str)) return false;
5-
62
try {
7-
new URL(str);
8-
9-
return true;
3+
const url = new URL(str);
4+
return url.protocol === "http:" || url.protocol === "https:";
105
} catch {
116
return false;
127
}

0 commit comments

Comments
 (0)