1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-17 09:00: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. * @param url - string to check.
*/ */
export const isUrl = (url: string): boolean => { export const isUrl = (url: string): boolean => {
const pattern = new RegExp( try {
'^(http://|https://)[a-z0-9]+([-.]{1}[a-z0-9]+)*.[a-z]{2,5}(:[0-9]{1,5})?(/.*)?$', const validUrl = new URL(url)
'gi' } catch (_) {
) return false
}
if (pattern.test(url)) return true return true
else
throw new Error(
`'${url}' is not a valid url. An example of a valid url is 'http://valid-url.com'.`
)
} }