isValidURL function update
parent
3443fbe685
commit
8449a3a14e
17
src/utils.ts
17
src/utils.ts
|
@ -7,16 +7,13 @@ const combineUrls = (piece1: string, piece2: string): string => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const isValidURL = (str: string): boolean => {
|
const isValidURL = (str: string): boolean => {
|
||||||
const pattern = new RegExp(
|
let url;
|
||||||
"^(https?:\\/\\/)?" + // protocol
|
try {
|
||||||
"((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|" + // domain name
|
url = new URL(str);
|
||||||
"((\\d{1,3}\\.){3}\\d{1,3}))" + // OR ip (v4) address
|
} catch (_) {
|
||||||
"(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*" + // port and path
|
return false;
|
||||||
"(\\?[;&a-z\\d%_.~+=-]*)?" + // query string
|
}
|
||||||
"(\\#[-a-z\\d_]*)?$",
|
return url.protocol === "http:" || url.protocol === "https:";
|
||||||
"i"
|
|
||||||
); // fragment locater
|
|
||||||
return !!pattern.test(str);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { combineUrls, isValidURL };
|
export { combineUrls, isValidURL };
|
||||||
|
|
Loading…
Reference in New Issue