mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-08 05:56:38 +00:00
16 lines
434 B
TypeScript
16 lines
434 B
TypeScript
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;
|
|
}
|
|
}
|
|
|