1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-03 02:30:06 +00:00

fix(utility): improved 'isUrl' utility

This commit is contained in:
Yury Shkoda
2021-04-21 08:11:13 +03:00
parent 0aa0ae65e0
commit 48442f7769

View File

@@ -3,14 +3,11 @@
* @param url - string to check.
*/
export const isUrl = (url: string): boolean => {
const pattern = new RegExp(
'^(http://|https://)[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(:[0-9]{1,5})?(/.*)?$',
'gi'
)
try {
const validUrl = new URL(url)
} catch (_) {
return false
}
if (pattern.test(url)) return true
else
throw new Error(
`'${url}' is not a valid url. An example of a valid url is 'http://valid-url.com'.`
)
return true
}