net-address
    Preparing search index...

    Class Ipv4Net

    Represents an IPv4 network.

    const addrRes = Ipv4Addr.from('192.168.0.1');
    const addr = Ipv4Addr.fromOrThrow('192.168.0.1');
    const network = Ipv4Net.fromAddr(addr, 24);

    v0.1.2

    Index
    family: "ipv4" = ...

    Address family of the network.

    v0.1.2

    size: number

    Size of the network (subnet mask length).

    v0.1.2

    • Assigns an address to the current network, effectively combining the network with the given address.

      Parameters

      • value: string | Ipv4Addr

        The other IPv4 address to combine with (e.g., 0.0.0.100)

      Returns CoreResult<Ipv4Addr, TypeError | RangeError>

      The combined IPv4 address as a CoreResult containing either the resulting Ipv4Addr or a RangeError if the address does not fit within the host portion of the network.

      const network = Ipv4Net.fromOrThrow('192.168.0.0/24');
      const result: CoreResult<Ipv4Addr, RangeError | TypeError> = network.assignAddress('0.0.0.100');
      const result: CoreResult<Ipv4Addr, RangeError | TypeError> = network.assignAddress(Ipv4Addr.fromOrThrow('0.0.0.100'))

      v0.2.0

    • Assigns an address to the current network, effectively combining the network with the given address.

      Parameters

      • other: string | Ipv4Addr

        The other IPv4 address to combine with (e.g., 0.0.0.100)

      Returns Ipv4Addr

      The combined IPv4 address as an Ipv4Addr instance. (e.g., combining 192.168.0.0/24 with 0.0.0.100 would result in 192.168.0.100)

      If the given address does not fit within the host portion of the network.

      const network = Ipv4Net.fromOrThrow('192.168.0.0/24');
      const combined = network.assignAddressOrThrow('0.0.0.100'); // Ipv4Addr(192.168.0.100)
      const combined = network.assignAddressOrThrow(Ipv4Addr.fromOrThrow('0.0.0.100')); // Ipv4Addr(192.168.0.100)

      v0.2.0

    • Checks if the given IPv4 address is contained within the network.

      Parameters

      Returns boolean

      true if the given address is contained within the network, otherwise false.

      v0.2.0

    • Checks if the current network contains the given child network.

      Parameters

      • child: Ipv4Net

        The child network to check for containment.

      Returns boolean

      true if the current network contains the child network, false otherwise.

      v0.2.0

    • Checks if the current network is equal to another network.

      Parameters

      • Optionalother: unknown

        The other network to compare with.

      Returns boolean

      true if the networks are equal, otherwise false.

      const isEqual = Ipv4Net.fromOrThrow('192.168.0.0/24').equals(Ipv4Net.fromOrThrow('192.168.0.0/24'));
      

      v0.2.0

    • Checks if the current network is a subnet of the given parent network.

      Parameters

      • parent: Ipv4Net

        The parent network to check against.

      Returns boolean

      true if the current network is a subnet of the parent network, false otherwise.

      v0.2.0

    • Gets the string representation of the IPv4 network.

      Returns string

      The IPv4 network as a string, e.g., 192.168.0.1/24.

      v0.2.0

    • Creates an IPv4 network from its string representation.

      Parameters

      • value: string

        The string representation of the IPv4 network, e.g., 192.168.0.1/24.

      Returns CoreResult<Ipv4Net, TypeError>

      A CoreResult containing the parsed Ipv4Net instance or a TypeError if parsing fails.

      const networkRes: CoreResult<Ipv4Net, TypeError> = Ipv4Net.from('192.168.0.1/24');
      

      v0.2.0

    • Creates an IPv4 network from address and a subnet mask length, throwing an error if creation fails.

      Parameters

      • address: Ipv4Addr

        The starting Ipv4Addr of the network.

      • size: number

        The size of the network (subnet mask length).

      Returns Ipv4Net

      The parsed Ipv4Net instance.

      If the network size is invalid.

      const network: Ipv4Net = Ipv4Net.fromAddrOrThrow(addr, 24);
      

      v0.2.0

    • Creates an IPv4 network from its string representation, throwing an error if parsing fails.

      Parameters

      • value: string

        The string representation of the IPv4 network, e.g., 192.168.0.1/24.

      Returns Ipv4Net

      The parsed Ipv4Net instance.

      If the string representation is invalid.

      const network: Ipv4Net = Ipv4Net.fromOrThrow('192.168.0.1/24');
      

      v0.2.0