function cidrSize
cidrSize<T extends Cidr>(cidr: T): T extends Cidrv6 ? bigint : number

Returns the total number of addresses in a CIDR block.

Dispatches to cidrv4Size or cidrv6Size based on the address type.

Examples

Example 1

import { assertEquals } from "@std/assert";
import { cidrSize, parseCidr } from "@hertzg/ip/cidr";

assertEquals(cidrSize(parseCidr("192.168.1.0/24")), 256);
assertEquals(cidrSize(parseCidr("fd00::/120")), 256n);

Type Parameters

T extends Cidr

Parameters

cidr: T

The CIDR block

Return Type

T extends Cidrv6 ? bigint : number

The total number of addresses (number for IPv4, bigint for IPv6)

Usage

import { cidrSize } from "cidr.ts";