(input: IpAddressInput)
| 1113 | * @since 4.0.0 |
| 1114 | */ |
| 1115 | export const ipFromInput = (input: IpAddressInput): Result.Result<IpAddress, NetAddressError> => { |
| 1116 | if (isIpAddress(input)) return Result.succeed(input) |
| 1117 | if (typeof input === "string") return ipFromString(input) |
| 1118 | if (input instanceof Uint8Array && input.length === 4) return Result.succeed(ipv4FromBytesUnsafe(input)) |
| 1119 | if (input instanceof Uint8Array && input.length === 16) return Result.succeed(ipv6FromBytesUnsafe(input)) |
| 1120 | if (Array.isArray(input) && isTupleOf(input, 4)) return ipv4FromOctets(input) |
| 1121 | if (Array.isArray(input) && isTupleOf(input, 8)) return ipv6FromSegments(input) |
| 1122 | return addressError(input, "expected an IP address, string, 4 octets, 8 segments, or 4 or 16 bytes") |
| 1123 | } |
| 1124 | |
| 1125 | /** |
| 1126 | * Converts a trusted `IpAddressInput` to an IP address, throwing on failure. |
no test coverage detected