import fetch from './fetch'; export const isValidURL = (url: string): boolean => { 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 return !!pattern.test(url); }; // Use checkUseSsl: false only if server url starts with http:// export const isSsl = (url: string): boolean => !/http:\/\//.test(url); export const isValidURLRequest = async (url: string) => { try { const result = await fetch(url); return result.status === 200; } catch { return false; } };