parseIpAddress
parseIpAddress parses a textual IPv4 or IPv6 address and returns an IpAddress?.
The function validates the complete input without contacting the network. Invalid text produces an absent optional value.
Signature
parseIpAddress(value: string): IpAddress?tyrus
import { IpAddress, parseIpAddress } from "tyrus:net";
const address: IpAddress? = parseIpAddress("192.0.2.10");
if (address) {
print(address.family); // "IPv4"
}Error Handling
error
tyrus
import { parseIpAddress } from "tyrus:net";
const address = parseIpAddress("not-an-ip");
print(address ?? "missing"); // "missing"Invalid input is represented by the absent optional result; this function does not throw NetError.
