1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-07 20:40:05 +00:00
Files
adapter/src/utils/isUrl.ts
2021-04-22 14:45:56 +03:00

18 lines
335 B
TypeScript

/**
* Checks if string is in URL format.
* @param str - string to check.
*/
export const isUrl = (str: string): boolean => {
const supportedProtocols = ['http:', 'https:']
try {
const url = new URL(str)
if (!supportedProtocols.includes(url.protocol)) return false
} catch (_) {
return false
}
return true
}