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:
@@ -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'.`
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user