diff --git a/src/parse.ts b/src/parse.ts index 2e85f9ce..6459d538 100644 --- a/src/parse.ts +++ b/src/parse.ts @@ -16,7 +16,7 @@ export interface ParsedAuth { export interface ParsedHost { hostname: string; - port: string; + port: number; } export function parseURL(input = "", defaultProto?: string): ParsedURL { @@ -68,7 +68,7 @@ export function parseHost(input = ""): ParsedHost { const [hostname, port] = (input.match(/([^/:]*):?(\d+)?/) || []).splice(1); return { hostname: decode(hostname), - port, + port: port ? Number.parseInt(port) : undefined, }; } diff --git a/test/parse.test.ts b/test/parse.test.ts index 8ee7fedb..a6147b30 100644 --- a/test/parse.test.ts +++ b/test/parse.test.ts @@ -92,7 +92,7 @@ describe("parseURL", () => { describe("parseHost", () => { const tests = [ - { input: "localhost:3000", out: { hostname: "localhost", port: "3000" } }, + { input: "localhost:3000", out: { hostname: "localhost", port: 3000 } }, { input: "google.com", out: { hostname: "google.com", port: undefined } }, ];