1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-03 10:40:06 +00:00
Files
adapter/src/utils/isUrl.ts
2020-09-08 16:07:02 +03:00

13 lines
343 B
TypeScript

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'
)
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'.`
)
}