MCPcopy Create free account
hub / github.com/Effect-TS/effect / ipv4FromString

Function ipv4FromString

packages/effect/src/net/NetAddress.ts:977–990  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

975 * @since 4.0.0
976 */
977export 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
992const parseIpv6Segments = (input: string): Result.Result<ReadonlyArray<number>, NetAddressError> => {
993 if (input.includes("[") || input.includes("]") || input.includes("%")) {

Callers 3

parseIpv6SegmentsFunction · 0.70
ipFromStringFunction · 0.70
ipv4FromInputFunction · 0.70

Calls 5

addressErrorFunction · 0.85
ipv4FromOctetsFunction · 0.85
someMethod · 0.80
splitMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected