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

Function inetAddressFromInput

packages/effect/src/net/NetAddress.ts:2001–2014  ·  view source on GitHub ↗
(input: InetAddressInput)

Source from the content-addressed store, hash-verified

1999 * @since 4.0.0
2000 */
2001export const inetAddressFromInput = (input: InetAddressInput): Result.Result<InetAddress, NetAddressError> => {
2002 if (isInetAddress(input)) return Result.succeed(input)
2003 if (typeof input === "string") return inetAddressFromString(input)
2004 if (!hasProperty(input, "address") || !hasProperty(input, "port")) {
2005 return addressError(input, "expected an address and port")
2006 }
2007 const { port, scopeId } = input
2008 return Result.flatMap(ipFromInput(input.address), (address): Result.Result<InetAddress, NetAddressError> => {
2009 if (isIpv6Address(address)) return inetAddressV6(address, port, { scopeId })
2010 return (scopeId ?? 0) === 0
2011 ? inetAddressV4(address, port)
2012 : addressError(input, "scopeId requires an IPv6 address")
2013 })
2014}
2015
2016/**
2017 * Converts a trusted `InetAddressInput` to an internet address, throwing on failure.

Callers 2

socketAddressFromInputFunction · 0.85

Calls 9

hasPropertyFunction · 0.90
isInetAddressFunction · 0.85
inetAddressFromStringFunction · 0.85
addressErrorFunction · 0.85
ipFromInputFunction · 0.85
isIpv6AddressFunction · 0.85
inetAddressV6Function · 0.85
inetAddressV4Function · 0.85
succeedMethod · 0.45

Tested by

no test coverage detected