cidrIntersect<T extends Cidr>(): (T extends Cidrv4 ? Cidrv4 : Cidrv6) | null
Returns the intersection of two CIDR blocks.
Dispatches to cidrv4Intersect or cidrv6Intersect based on the address type. Throws TypeError when mixing IPv4 and IPv6 CIDRs. The result matches the dialect of the inputs, and is masked when they disagree (ADR 0006).
IPv4 intersection
IPv4 intersection
import { assertEquals } from "@std/assert"; import { cidrIntersect, parseCidr, stringifyCidr } from "@hertzg/ip/cidr"; const result = cidrIntersect(parseCidr("10.0.0.0/8"), parseCidr("10.1.0.0/16")); assertEquals(result && stringifyCidr(result), "10.1.0.0/16");
T extends Cidr