2022-01-12 12:54:04 +00:00
|
|
|
export const isValidURL = (url: string): boolean => {
|
2021-09-13 20:41:05 +00:00
|
|
|
const pattern = new RegExp(
|
|
|
|
'^(https?:\\/\\/)?' + // protocol
|
|
|
|
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
|
|
|
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
|
|
|
|
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
|
|
|
|
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
|
|
|
|
'(\\#[-a-z\\d_]*)?$',
|
|
|
|
'i'
|
|
|
|
); // fragment locator
|
2020-03-20 16:26:50 +00:00
|
|
|
return !!pattern.test(url);
|
|
|
|
};
|
2020-05-04 20:20:45 +00:00
|
|
|
|
|
|
|
// Use useSsl: false only if server url starts with http://
|
2022-01-12 12:54:04 +00:00
|
|
|
export const useSsl = (url: string): boolean => !/http:\/\//.test(url);
|