(url)
| 1233 | return value != null && value[0] === "h" && value[1] === "t" && value[2] === "t" && value[3] === "p" && (value[4] === ":" || value[4] === "s" && value[5] === ":"); |
| 1234 | } |
| 1235 | function parseURL(url) { |
| 1236 | if (typeof url === "string") { |
| 1237 | url = new URL(url); |
| 1238 | if (!isHttpOrHttpsPrefixed(url.origin || url.protocol)) { |
| 1239 | throw new InvalidArgumentError("Invalid URL protocol: the URL must start with `http:` or `https:`."); |
| 1240 | } |
| 1241 | return url; |
| 1242 | } |
| 1243 | if (!url || typeof url !== "object") { |
| 1244 | throw new InvalidArgumentError("Invalid URL: The URL argument must be a non-null object."); |
| 1245 | } |
| 1246 | if (!(url instanceof URL)) { |
| 1247 | if (url.port != null && url.port !== "" && isValidPort(url.port) === false) { |
| 1248 | throw new InvalidArgumentError("Invalid URL: port must be a valid integer or a string representation of an integer."); |
| 1249 | } |
| 1250 | if (url.path != null && typeof url.path !== "string") { |
| 1251 | throw new InvalidArgumentError("Invalid URL path: the path must be a string or null/undefined."); |
| 1252 | } |
| 1253 | if (url.pathname != null && typeof url.pathname !== "string") { |
| 1254 | throw new InvalidArgumentError("Invalid URL pathname: the pathname must be a string or null/undefined."); |
| 1255 | } |
| 1256 | if (url.hostname != null && typeof url.hostname !== "string") { |
| 1257 | throw new InvalidArgumentError("Invalid URL hostname: the hostname must be a string or null/undefined."); |
| 1258 | } |
| 1259 | if (url.origin != null && typeof url.origin !== "string") { |
| 1260 | throw new InvalidArgumentError("Invalid URL origin: the origin must be a string or null/undefined."); |
| 1261 | } |
| 1262 | if (!isHttpOrHttpsPrefixed(url.origin || url.protocol)) { |
| 1263 | throw new InvalidArgumentError("Invalid URL protocol: the URL must start with `http:` or `https:`."); |
| 1264 | } |
| 1265 | const port = url.port != null ? url.port : url.protocol === "https:" ? 443 : 80; |
| 1266 | let origin = url.origin != null ? url.origin : `${url.protocol || ""}//${url.hostname || ""}:${port}`; |
| 1267 | let path4 = url.path != null ? url.path : `${url.pathname || ""}${url.search || ""}`; |
| 1268 | if (origin[origin.length - 1] === "/") { |
| 1269 | origin = origin.slice(0, origin.length - 1); |
| 1270 | } |
| 1271 | if (path4 && path4[0] !== "/") { |
| 1272 | path4 = `/${path4}`; |
| 1273 | } |
| 1274 | return new URL(`${origin}${path4}`); |
| 1275 | } |
| 1276 | if (!isHttpOrHttpsPrefixed(url.origin || url.protocol)) { |
| 1277 | throw new InvalidArgumentError("Invalid URL protocol: the URL must start with `http:` or `https:`."); |
| 1278 | } |
| 1279 | return url; |
| 1280 | } |
| 1281 | function parseOrigin(url) { |
| 1282 | url = parseURL(url); |
| 1283 | if (url.pathname !== "/" || url.search || url.hash) { |
no test coverage detected