cidrMerge<T extends Cidr>(cidrs: readonly T[]): T[]
Merges CIDR blocks into the minimal covering set.
Dispatches to cidrv4Merge or cidrv6Merge based on the address type of the first element. All elements must be the same IP version. The result matches the dialect of the inputs, and is masked when they disagree (ADR 0006).
Merge IPv4 CIDRs
Merge IPv4 CIDRs
import { assertEquals } from "@std/assert"; import { cidrMerge, parseCidr, stringifyCidr } from "@hertzg/ip/cidr"; const result = cidrMerge([parseCidr("10.0.0.0/25"), parseCidr("10.0.0.128/25")]); assertEquals(result.map((c) => stringifyCidr(c)), ["10.0.0.0/24"]);
T extends Cidr
cidrs: readonly T[]
The CIDR blocks to merge
T[]
Minimal set of non-overlapping CIDR blocks, sorted by address