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

feat: added isUrl validation utility

This commit is contained in:
Yury Shkoda
2020-09-07 16:32:53 +03:00
parent 1f970e1102
commit 0eb9bc43ff
6 changed files with 33 additions and 6 deletions

12
src/utils/isUrl.ts Normal file
View File

@@ -0,0 +1,12 @@
export const isUrl = (url: string): boolean => {
const pattern = new RegExp(
'^(http://www.|https://www.|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'.`
)
}