a tool for shared writing and social publishing
1//From https://github.com/segmentio/is-url/blob/master/index.js
2//
3var protocolAndDomainRE = /^(?:\w+:)?\/\/(\S+)$/;
4
5var localhostDomainRE = /^localhost[\:?\d]*(?:[^\:?\d]\S*)?$/;
6var nonLocalhostDomainRE = /^[^\s\.]+\.\S{2,}$/;
7
8export function isUrl(str: string) {
9 return str.includes(".");
10}
11
12export function betterIsUrl(string: string) {
13 if (typeof string !== "string") {
14 return false;
15 }
16
17 var match = string.match(protocolAndDomainRE);
18 if (!match) {
19 return false;
20 }
21
22 var everythingAfterProtocol = match[1];
23 if (!everythingAfterProtocol) {
24 return false;
25 }
26
27 if (
28 localhostDomainRE.test(everythingAfterProtocol) ||
29 nonLocalhostDomainRE.test(everythingAfterProtocol)
30 ) {
31 return true;
32 }
33
34 return false;
35}