Skip to content

Instantly share code, notes, and snippets.

@pujansrt
Last active August 31, 2018 10:31
Show Gist options
  • Save pujansrt/ca9cc35cb0feafdadcaeee430916b66a to your computer and use it in GitHub Desktop.
Save pujansrt/ca9cc35cb0feafdadcaeee430916b66a to your computer and use it in GitHub Desktop.
async getUrlInfo(url: string) {
const reg = new RegExp("https?://([a-z0-9]+[.])*.?ea[.]com");
const reg2 = new RegExp("^(?:http(s)?:\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&'\\(\\)\\*\\+,;=.]+$");
async function reachability() {
const responseReachable: any = await fetch(url, {method: 'HEAD'}).catch(() => false);
return responseReachable.status === 200;
}
return {
valid: reg2.test(url),
internal: reg.test(url),
reachable: reachability()
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment