Add Smart Host Parsing

This commit is contained in:
Pallavi
2025-08-22 13:07:03 +05:30
parent 60d8831399
commit 9557f755a5
3 changed files with 207 additions and 152 deletions

View File

@@ -0,0 +1,15 @@
export function parseHostTarget(input: string) {
try {
const normalized = input.match(/^https?:\/\//) ? input : `http://${input}`;
const url = new URL(normalized);
const protocol = url.protocol.replace(":", ""); // http | https
const host = url.hostname;
const port = url.port ? parseInt(url.port, 10) : protocol === "https" ? 443 : 80;
return { protocol, host, port };
} catch {
return null;
}
}