MCPcopy
hub / github.com/webpack/webpack-dev-server / formatURL

Function formatURL

client-src/index.js:607–671  ·  view source on GitHub ↗
(objURL)

Source from the content-addressed store, hash-verified

605 * @returns {string} formatted url
606 */
607const formatURL = (objURL) => {
608 let protocol = objURL.protocol || "";
609
610 if (protocol && protocol.slice(-1) !== ":") {
611 protocol += ":";
612 }
613
614 let auth = objURL.auth || "";
615
616 if (auth) {
617 auth = encodeURIComponent(auth);
618 auth = auth.replace(/%3A/i, ":");
619 auth += "@";
620 }
621
622 let host = "";
623
624 if (objURL.hostname) {
625 host =
626 auth +
627 (objURL.hostname.indexOf(":") === -1
628 ? objURL.hostname
629 : `[${objURL.hostname}]`);
630
631 if (objURL.port) {
632 host += `:${objURL.port}`;
633 }
634 }
635
636 let pathname = objURL.pathname || "";
637
638 if (objURL.slashes) {
639 host = `//${host || ""}`;
640
641 if (pathname && pathname.charAt(0) !== "/") {
642 pathname = `/${pathname}`;
643 }
644 } else if (!host) {
645 host = "";
646 }
647
648 let search = objURL.search || "";
649
650 if (search && search.charAt(0) !== "?") {
651 search = `?${search}`;
652 }
653
654 let hash = objURL.hash || "";
655
656 if (hash && hash.charAt(0) !== "#") {
657 hash = `#${hash}`;
658 }
659
660 pathname = pathname.replace(
661 /[?#]/g,
662 /**
663 * @param {string} match matched string
664 * @returns {string} encoded URI component

Callers 1

createSocketURLFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…