(input: string)
| 975 | * @since 4.0.0 |
| 976 | */ |
| 977 | export const ipv4FromString = (input: string): Result.Result<Ipv4Address, NetAddressError> => { |
| 978 | const parts = input.split(".") |
| 979 | if (parts.length !== 4 || parts.some((part) => !/^\d{1,3}$/.test(part))) { |
| 980 | return addressError(input, "expected exactly four decimal octets") |
| 981 | } |
| 982 | if (parts.some((part) => part.length > 1 && part[0] === "0")) { |
| 983 | return addressError(input, "leading zeroes are not allowed") |
| 984 | } |
| 985 | const octets = parts.map(Number) |
| 986 | if (octets.some((part) => part > 255)) { |
| 987 | return addressError(input, "octets must be at most 255") |
| 988 | } |
| 989 | return ipv4FromOctets([octets[0], octets[1], octets[2], octets[3]]) |
| 990 | } |
| 991 | |
| 992 | const parseIpv6Segments = (input: string): Result.Result<ReadonlyArray<number>, NetAddressError> => { |
| 993 | if (input.includes("[") || input.includes("]") || input.includes("%")) { |
no test coverage detected