Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

IpInterface unstable

IPv4 and IPv6 interface addresses that preserve host bits alongside a prefix length.

22 exports Since v4.0.0 Source

Constructors

fromInput

unstable
Since v4.0.0

Converts an IpInterfaceInput to an interface address, parsing strings like fromString with the given options, converting parts like make, and returning interface addresses unchanged.

Signature

declare function fromInput(input: IpInterfaceInput, options?: ParseOptions): Result<IpInterface<IpAddress>, NetAddressError>
Since v4.0.0

Converts an Ipv4InterfaceInput to an IPv4 interface address, parsing strings like ipv4FromString with the given options, converting parts like make, and returning interface addresses unchanged.

Signature

declare function ipv4FromInput(input: Ipv4InterfaceInput, options?: ParseOptions): Result<Ipv4Interface, NetAddressError>
Since v4.0.0

Converts an Ipv6InterfaceInput to an IPv6 interface address, parsing strings like ipv6FromString with the given options, converting parts like make, and returning interface addresses unchanged.

Signature

declare function ipv6FromInput(input: Ipv6InterfaceInput, options?: ParseOptions): Result<Ipv6Interface, NetAddressError>

make

unstable
Since v4.0.0

Creates an interface address while preserving all address bits.

Signature

declare function make<A extends IpAddress>(address: A, prefixLength: number): Result<IpInterface<A>, NetAddressError>

Decoding

fromString

unstable
Since v4.0.0

Parses an IP interface address while preserving host bits.

Details

A missing prefix defaults to the address width. Use prefix: "required" to require one.

Signature

declare function fromString(input: string, options?: ParseOptions): Result<IpInterface<IpAddress>, NetAddressError>
Since v4.0.0

Parses an IPv4 interface address while preserving host bits.

Details

A missing prefix defaults to 32. Use prefix: "required" to require one.

Signature

declare function ipv4FromString(input: string, options?: ParseOptions): Result<Ipv4Interface, NetAddressError>
Since v4.0.0

Parses an IPv6 interface address while preserving host bits.

Details

A missing prefix defaults to 128. Use prefix: "required" to require one.

Signature

declare function ipv6FromString(input: string, options?: ParseOptions): Result<Ipv6Interface, NetAddressError>

Encoding

format

unstable
Since v4.0.0

Formats an interface address using canonical address text and its decimal prefix length.

Signature

declare function format(self: IpInterface): string

Guards

Since v4.0.0

Returns true when a value is an IP interface address.

Signature

declare function isIpInterface(u: unknown): u is IpInterface<IpAddress>
Since v4.0.0

Returns true when a value is an IPv4 interface address.

Signature

declare function isIpv4Interface(u: unknown): u is Ipv4Interface
Since v4.0.0

Returns true when a value is an IPv6 interface address.

Signature

declare function isIpv6Interface(u: unknown): u is Ipv6Interface

Models

IpInterface

interface unstable
Since v4.0.0

An IP host address and prefix length. Host bits and any verified address refinements are preserved because the address is retained unchanged. Code that computes different address bits must widen to the IPv4 or IPv6 family, or validate the resulting address before treating it as refined.

Signature

interface IpInterface<out A extends NetAddress.IpAddress = NetAddress.IpAddress> extends Equal, Hash, Inspectable {
readonly _tag: "IpInterface";
readonly "~effect/net/IpInterface": "~effect/net/IpInterface";
readonly address: A;
readonly prefixLength: number;
}

IpInterfaceInput

type unstable
Since v4.0.0

An interface address, or a string or parts to convert to one.

Signature

type IpInterfaceInput = IpInterface | string | IpInterfaceParts

IpInterfaceParts

interface unstable
Since v4.0.0

An address and prefix length, generic over the accepted address input.

See

  • make for the checked constructor

Signature

interface IpInterfaceParts<A extends NetAddress.IpAddressInput = NetAddress.IpAddressInput> {
readonly address: A;
readonly prefixLength: number;
}

Ipv4Interface

type unstable
Since v4.0.0

An IPv4 host address and prefix length.

Signature

type Ipv4Interface = IpInterface<NetAddress.Ipv4Address>

Ipv4InterfaceInput

type unstable
Since v4.0.0

An IPv4 interface address, or a string or parts to convert to one.

Signature

type Ipv4InterfaceInput = Ipv4Interface | string | IpInterfaceParts<NetAddress.Ipv4AddressInput>

Ipv6Interface

type unstable
Since v4.0.0

An IPv6 host address and prefix length.

Signature

type Ipv6Interface = IpInterface<NetAddress.Ipv6Address>

Ipv6InterfaceInput

type unstable
Since v4.0.0

An IPv6 interface address, or a string or parts to convert to one.

Signature

type Ipv6InterfaceInput = Ipv6Interface | string | IpInterfaceParts<NetAddress.Ipv6AddressInput>

Other

IpInterface

unstable
Since v4.0.0

Companion types for parsing IP interface addresses.

Unsafe

Since v4.0.0

Converts a trusted IpInterfaceInput to an interface address, throwing on failure.

Signature

declare function fromInputUnsafe(input: IpInterfaceInput, options?: ParseOptions): IpInterface
Since v4.0.0

Parses a trusted interface address, throwing on failure.

Signature

declare function fromStringUnsafe(input: string, options?: ParseOptions): IpInterface

makeUnsafe

unstable
Since v4.0.0

Creates a trusted interface address, throwing when its prefix length is invalid.

Signature

declare function makeUnsafe<A extends IpAddress>(address: A, prefixLength: number): IpInterface<A>