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