MCPcopy Create free account
hub / github.com/BrainicHQ/DoHSpeedTest / validateAndExtractHost

Function validateAndExtractHost

script.js:402–411  ·  view source on GitHub ↗
(input)

Source from the content-addressed store, hash-verified

400}
401
402function validateAndExtractHost(input) {
403 try {
404 const url = new URL(input);
405 if (url.protocol !== "http:" && url.protocol !== "https:") throw new Error();
406 return url.hostname;
407 } catch {
408 const hostnameRegex = /^(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.[A-Za-z]{2,})+$/;
409 return hostnameRegex.test(input) ? input : null;
410 }
411}
412
413$('addHostname').addEventListener('click', () => {
414 const input = $('newWebsite');

Callers 2

script.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected