cidr-block - v2.1.1
    Preparing search index...

    Class Ipv6Address

    Represents an IPv6 address with utility methods for manipulation and comparison.

    While you can instantiate this class directly, it is recommended to use the ipv6.address shorthand method from the ipv6 namespace instead.

    import { ipv6 } from 'cidr-block';

    // Recommended: use the ipv6 namespace shorthand
    const addr1 = ipv6.address("2001:db8::1");
    const addr2 = ipv6.address(42540766411282592856903984951653826561n);
    const addr3 = ipv6.address([0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]);
    import { ipv6 } from 'cidr-block';

    const addr = ipv6.address("2001:db8::1");
    addr.toString(); // "2001:db8::1" (compressed)
    addr.toFullString(); // "2001:0db8:0000:0000:0000:0000:0000:0001"
    addr.toBigInt(); // 42540766411282592856903984951653826561n
    addr.hextets(); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]
    import { ipv6 } from 'cidr-block';

    const addr = ipv6.address("2001:db8::1");
    addr.equals("2001:db8::1"); // true
    addr.isGreaterThan("2001:db8::0"); // true
    addr.isLessThan("2001:db8::2"); // true
    import { ipv6 } from 'cidr-block';

    const addr = ipv6.address("2001:db8::1");
    addr.nextAddress()?.toString(); // "2001:db8::2"
    addr.previousAddress()?.toString(); // "2001:db8::"
    import { ipv6 } from 'cidr-block';

    ipv6.address("::1").isLoopbackAddress(); // true
    ipv6.address("fc00::1").isUniqueLocalAddress(); // true
    ipv6.address("fe80::1").isLinkLocalAddress(); // true
    ipv6.address("ff02::1").isMulticastAddress(); // true
    Index

    Constructors

    Methods

    • Compares two IPv6 addresses for equality.

      Parameters

      Returns boolean

      true if both IPv6 addresses are equal

      import { ipv6 } from 'cidr-block';

      const addr = ipv6.address("2001:db8::1");
      addr.equals("2001:db8::1"); // true
      addr.equals("2001:0db8:0:0:0:0:0:1"); // true
      addr.equals(ipv6.address("2001:db8::2")); // false
    • Checks if there is a next sequential IPv6 address. This would only return false if the current address is the maximum possible value.

      Returns boolean

      true if there is a next IPv6 address.

      import { ipv6 } from 'cidr-block';

      ipv6.address("2001:db8::1").hasNextAddress(); // true
      ipv6.address("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff").hasNextAddress(); // false
    • Checks if there is a previous sequential IPv6 address. This would only return false if the current address is the minimum possible value (::).

      Returns boolean

      true if there is a previous IPv6 address.

      import { ipv6 } from 'cidr-block';

      ipv6.address("2001:db8::1").hasPreviousAddress(); // true
      ipv6.address("::").hasPreviousAddress(); // false
    • Gets the hextets of the IPv6 address.

      Returns Ipv6AddressHextets

      An array of eight numbers representing the hextets of the IPv6 address.

      import { ipv6 } from 'cidr-block';

      const addr = ipv6.address("2001:db8::1");
      addr.hextets(); // [0x2001, 0xdb8, 0, 0, 0, 0, 0, 1]
    • Checks if the IPv6 address is a documentation address (2001:db8::/32)

      Returns boolean

      true if the IPv6 address is a documentation address

      import { ipv6 } from 'cidr-block';

      ipv6.address("2001:db8::1").isDocumentationAddress(); // true
      ipv6.address("2001:db8:1234::1").isDocumentationAddress(); // true
      ipv6.address("2001:470::1").isDocumentationAddress(); // false
    • Compares if this IPv6 address is greater than another IPv6 address.

      Parameters

      Returns boolean

      true if this IPv6 address is greater than the other IPv6 address

      import { ipv6 } from 'cidr-block';

      const addr = ipv6.address("2001:db8::1");
      addr.isGreaterThan("2001:db8::"); // true
      addr.isGreaterThan("2001:db8::1"); // false
      addr.isGreaterThan("2001:db8::2"); // false
    • Compares if this IPv6 address is greater than or equal to another IPv6 address.

      Parameters

      Returns boolean

      true if this IPv6 address is greater than or equal to the other IPv6 address

      import { ipv6 } from 'cidr-block';

      const addr = ipv6.address("2001:db8::1");
      addr.isGreaterThanOrEqual("2001:db8::"); // true
      addr.isGreaterThanOrEqual("2001:db8::1"); // true
      addr.isGreaterThanOrEqual("2001:db8::2"); // false
    • Checks if the IPv6 address is an IPv4-mapped IPv6 address (::ffff:0:0/96)

      Returns boolean

      true if the IPv6 address is an IPv4-mapped address

      import { ipv6 } from 'cidr-block';

      ipv6.address("::ffff:192.168.1.1").isIPv4MappedAddress(); // true
      ipv6.address("::ffff:c0a8:0101").isIPv4MappedAddress(); // true
      ipv6.address("2001:db8::1").isIPv4MappedAddress(); // false
    • Compares if this IPv6 address is less than another IPv6 address.

      Parameters

      Returns boolean

      true if this IPv6 address is less than the other IPv6 address

      import { ipv6 } from 'cidr-block';

      const addr = ipv6.address("2001:db8::1");
      addr.isLessThan("2001:db8::2"); // true
      addr.isLessThan("2001:db8::1"); // false
      addr.isLessThan("2001:db8::"); // false
    • Compares if this IPv6 address is less than or equal to another IPv6 address.

      Parameters

      Returns boolean

      true if this IPv6 address is less than or equal to the other IPv6 address

      import { ipv6 } from 'cidr-block';

      const addr = ipv6.address("2001:db8::1");
      addr.isLessThanOrEqual("2001:db8::2"); // true
      addr.isLessThanOrEqual("2001:db8::1"); // true
      addr.isLessThanOrEqual("2001:db8::"); // false
    • Checks if the IPv6 address is a link-local address (fe80::/10)

      Returns boolean

      true if the IPv6 address is a link-local address

      import { ipv6 } from 'cidr-block';

      ipv6.address("fe80::1").isLinkLocalAddress(); // true
      ipv6.address("2001:db8::1").isLinkLocalAddress(); // false
    • Checks if the IPv6 address is the loopback address (::1)

      Returns boolean

      true if the IPv6 address is the loopback address

      import { ipv6 } from 'cidr-block';

      ipv6.address("::1").isLoopbackAddress(); // true
      ipv6.address("2001:db8::1").isLoopbackAddress(); // false
    • Checks if the IPv6 address is a multicast address (ff00::/8)

      Returns boolean

      true if the IPv6 address is a multicast address

      import { ipv6 } from 'cidr-block';

      ipv6.address("ff02::1").isMulticastAddress(); // true
      ipv6.address("2001:db8::1").isMulticastAddress(); // false
    • Checks if the IPv6 address is a unique local address (fc00::/7). These are the IPv6 equivalent of RFC 1918 private addresses.

      Returns boolean

      true if the IPv6 address is a unique local address

      import { ipv6 } from 'cidr-block';

      ipv6.address("fc00::1").isUniqueLocalAddress(); // true
      ipv6.address("fd00::1").isUniqueLocalAddress(); // true
      ipv6.address("2001:db8::1").isUniqueLocalAddress(); // false
    • Checks if the IPv6 address is the unspecified address (::)

      Returns boolean

      true if the IPv6 address is the unspecified address

      import { ipv6 } from 'cidr-block';

      ipv6.address("::").isUnspecifiedAddress(); // true
      ipv6.address("2001:db8::1").isUnspecifiedAddress(); // false
    • Gets the next sequential IPv6 address.

      Returns Ipv6Address | undefined

      The next IPv6 address, or undefined if the current address is the maximum possible value.

      import { ipv6 } from 'cidr-block';

      const addr = ipv6.address("2001:db8::1");
      addr.nextAddress()?.toString(); // "2001:db8::2"

      const maxAddr = ipv6.address("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
      maxAddr.nextAddress(); // undefined
    • Gets the previous sequential IPv6 address.

      Returns Ipv6Address | undefined

      The previous IPv6 address, or undefined if the current address is the minimum possible value.

      import { ipv6 } from 'cidr-block';

      const addr = ipv6.address("2001:db8::1");
      addr.previousAddress()?.toString(); // "2001:db8::"

      const minAddr = ipv6.address("::");
      minAddr.previousAddress(); // undefined
    • Converts the IPv6 address to its BigInt representation.

      Returns bigint

      The IPv6 address as a BigInt.

      import { ipv6 } from 'cidr-block';

      const addr = ipv6.address("2001:db8::1");
      addr.toBigInt(); // 42540766411282592856903984951653826561n
    • Returns the binary string representation of the IPv6 address.

      Returns string

      The IPv6 address as a binary string with colons separating hextets.

      import { ipv6 } from 'cidr-block';

      const addr = ipv6.address("::1");
      addr.toBinaryString();
      // "0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000000:0000000000000001"
    • Returns the full (expanded) string representation of the IPv6 address.

      Returns string

      The IPv6 address as a full string with all hextets expanded.

      import { ipv6 } from 'cidr-block';

      const addr = ipv6.address("2001:db8::1");
      addr.toFullString(); // "2001:0db8:0000:0000:0000:0000:0000:0001"
    • Returns the compressed string representation of the IPv6 address. Uses :: notation for the longest run of consecutive zero hextets.

      Returns string

      The IPv6 address as a compressed string.

      import { ipv6 } from 'cidr-block';

      const addr = ipv6.address("2001:0db8:0000:0000:0000:0000:0000:0001");
      addr.toString(); // "2001:db8::1"