IpNetwork
Pure, canonical IPv4 and IPv6 network prefixes using CIDR notation.
Constructors
fromAddress
Creates the canonical network containing an address by clearing its host bits.
Gotchas
The returned network's address can differ from the input address.
Signature
declare function fromAddress<A extends IpAddress>(address: A, prefixLength: number): Result<IpNetwork<A>, NetAddressError>Creates a network prefix when the address has no host bits set.
Gotchas
Use fromAddress when a host address should be truncated to its containing network.
Signature
declare function make<A extends IpAddress>(address: A, prefixLength: number): Result<IpNetwork<A>, NetAddressError>Conversions
fromInterface
Returns the canonical network containing an interface address.
Signature
declare function fromInterface<A extends IpAddress>(self: IpInterface<A>): IpNetwork<A>Decoding
fromString
Parses a strict IPv4 or IPv6 network prefix in CIDR notation.
Signature
declare function fromString(input: string): Result<IpNetwork<IpAddress>, NetAddressError>ipv4FromString
Parses a strict IPv4 network prefix in CIDR notation.
Signature
declare function ipv4FromString(input: string): Result<Ipv4Network, NetAddressError>ipv6FromString
Parses a strict IPv6 network prefix in CIDR notation.
Signature
declare function ipv6FromString(input: string): Result<Ipv6Network, NetAddressError>Encoding
Getters
addressCount
Returns the exact number of addresses in a network prefix.
Signature
declare function addressCount(self: IpNetwork): bigintfirstAddress
Returns the lowest address in a network prefix.
Signature
declare function firstAddress<A extends IpAddress>(self: IpNetwork<A>): AlastAddress
Returns the numerically greatest address in a network prefix.
Signature
declare function lastAddress<A extends IpAddress>(self: IpNetwork<A>): AGuards
isIpNetwork
Returns true when a value is an IPv4 or IPv6 network prefix.
Signature
declare function isIpNetwork(u: unknown): u is IpNetwork<IpAddress>isIpv4Network
Returns true when a value is an IPv4 network prefix.
Signature
declare function isIpv4Network(u: unknown): u is Ipv4NetworkisIpv6Network
Returns true when a value is an IPv6 network prefix.
Signature
declare function isIpv6Network(u: unknown): u is Ipv6NetworkModels
An immutable canonical IP network prefix.
Signature
interface IpNetwork<out A extends NetAddress.IpAddress = NetAddress.IpAddress> extends Equal, Hash { readonly _tag: "IpNetwork"; readonly "~effect/net/IpNetwork": "~effect/net/IpNetwork"; readonly address: A; readonly prefixLength: number; toJSON(): string; toString(): string;}Ipv4Network type
An immutable canonical IPv4 network prefix.
Signature
type Ipv4Network = IpNetwork<NetAddress.Ipv4Address>Ipv6Network type
An immutable canonical IPv6 network prefix.
Signature
type Ipv6Network = IpNetwork<NetAddress.Ipv6Address>Predicates
Returns true when a network prefix contains an IP address.
Signature
declare const contains: { (address: IpAddress): (self: IpNetwork) => boolean; (self: IpNetwork, address: IpAddress): boolean;}containsNetwork
Returns true when a network prefix contains every address in another network prefix.
Signature
declare const containsNetwork: { (other: IpNetwork): (self: IpNetwork) => boolean; (self: IpNetwork, other: IpNetwork): boolean;}Returns true when two network prefixes contain at least one common address.
Signature
declare const overlaps: { (other: IpNetwork): (self: IpNetwork) => boolean; (self: IpNetwork, other: IpNetwork): boolean;}Unsafe
fromAddressUnsafe
Creates the network containing a trusted address, throwing when its prefix is invalid.
Signature
declare function fromAddressUnsafe<A extends IpAddress>(address: A, prefixLength: number): IpNetwork<A>fromStringUnsafe
Parses a trusted network prefix in CIDR notation, throwing on failure.
Signature
declare function fromStringUnsafe(input: string): IpNetworkmakeUnsafe
Creates a trusted network prefix, throwing when its address or prefix is invalid.
Signature
declare function makeUnsafe<A extends IpAddress>(address: A, prefixLength: number): IpNetwork<A>