Parse a target string into hostname and optional port. Supports multiple formats: bare hostname, host:port, URL, IPv6 with brackets.
Target string (e.g., "example.com", "example.com:8443", "https://example.com")
Parsed target with hostname and optional port
If input is empty or invalid
If URL protocol is not http/https
If port number is invalid (not 1-65535)
If IPv6 format is malformed
parseTarget('google.com') // { hostname: 'google.com' }parseTarget('google.com:443') // { hostname: 'google.com', port: 443 }parseTarget('https://google.com') // { hostname: 'google.com' }parseTarget('[::1]:8080') // { hostname: '[::1]', port: 8080 } Copy
parseTarget('google.com') // { hostname: 'google.com' }parseTarget('google.com:443') // { hostname: 'google.com', port: 443 }parseTarget('https://google.com') // { hostname: 'google.com' }parseTarget('[::1]:8080') // { hostname: '[::1]', port: 8080 }
Parse a target string into hostname and optional port. Supports multiple formats: bare hostname, host:port, URL, IPv6 with brackets.