import { NonLoopbackHostError } from "./errors.js";

export function assertLoopbackHost(host: string): "127.0.0.1" | "::1" {
  if (host === "127.0.0.1") {
    return "127.0.0.1";
  }
  if (host === "::1") {
    return "::1";
  }
  throw new NonLoopbackHostError(host);
}

export function formatServerUrl(host: "127.0.0.1" | "::1", port: number): string {
  if (host === "::1") {
    return `http://[::1]:${String(port)}`;
  }
  return `http://127.0.0.1:${String(port)}`;
}
