Something went wrong. Try again.
a tool for shared writing and social publishing
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536//From https://github.com/segmentio/is-url/blob/master/index.js//var protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/;
var localhostDomainRE = /^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/;var nonLocalhostDomainRE = /^[^\s\.]+\.\S{2,}$/;
export function isUrl(str: string) { return str.includes(".");}
export function betterIsUrl(string: string) { if (typeof string !== "string") { return false; }
var match = string.match(protocolAndDomainRE); if (!match) { return false; }
var everythingAfterProtocol = match[1]; if (!everythingAfterProtocol) { return false; }
if ( localhostDomainRE.test(everythingAfterProtocol) || nonLocalhostDomainRE.test(everythingAfterProtocol) ) { return true; }
return false;}