MCPcopy Index your code
hub / github.com/nodejs/node / getHostname

Function getHostname

lib/url.js:508–527  ·  view source on GitHub ↗
(self, rest, hostname, url)

Source from the content-addressed store, hash-verified

506};
507
508function getHostname(self, rest, hostname, url) {
509 for (let i = 0; i < hostname.length; ++i) {
510 const code = hostname.charCodeAt(i);
511 const isValid = (code !== CHAR_FORWARD_SLASH &&
512 code !== CHAR_BACKWARD_SLASH &&
513 code !== CHAR_HASH &&
514 code !== CHAR_QUESTION_MARK &&
515 code !== CHAR_COLON);
516
517 if (!isValid) {
518 // If leftover starts with :, then it represents an invalid port.
519 if (code === CHAR_COLON) {
520 throw new ERR_INVALID_ARG_VALUE('url', 'Invalid port in url', url);
521 }
522 self.hostname = hostname.slice(0, i);
523 return `/${hostname.slice(i)}${rest}`;
524 }
525 }
526 return rest;
527}
528
529// Escaped characters. Use empty strings to fill up unused entries.
530// Using Array is faster than Object/Map

Callers 2

url.jsFile · 0.70
os.jsFile · 0.70

Calls 1

sliceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…