type alias Cidrv6

Represents an IPv6 CIDR block.

Contains only the parsed values from the CIDR notation, in whichever of the two dialects it was written: a prefix length (PrefixedCidrv6) or a network mask (MaskedCidrv6). Every cidrv6* operation accepts both and works on the mask internally; a result that has a dialect matches the input, and mixed inputs give the mask form (ADR 0006).

The two branches exclude each other's key, so an object literal cannot carry both. If a value smuggled past the type checker does carry both, mask wins, because the mask is the form the operations compute on; nothing checks for the case at runtime.

Examples

The two dialects describe the same block

import { assertEquals } from "@std/assert";
import { type Cidrv6, cidrv6Size, parseCidrv6 } from "@hertzg/ip/cidrv6";

const prefixed: Cidrv6 = parseCidrv6("2001:db8::/32");
const masked: Cidrv6 = {
  address: prefixed.address,
  mask: 0xFFFFFFFF000000000000000000000000n,
};

assertEquals(cidrv6Size(masked), cidrv6Size(prefixed));

Definition

Usage

import { type Cidrv6 } from "cidr.ts";