NetworkList class
A single-family list of networks, stored as sorted binary ranges and searched in O(log n).
Signature:
export declare class NetworkList
Remarks
One family per list — the record widths differ, so IPv4 and IPv6 cannot share a buffer. Reach for Networks unless you know the family up front; it holds one of these per family and dispatches on the address it is given.
Each network is one record of two addresses, start and end: 8 bytes for IPv4 and 32 for IPv6, so memory is linear in the number of networks and independent of how large each network is. Records are sorted at construction, which is what makes the binary search in NetworkList.includes() valid.
Instances are effectively immutable — every field is readonly and there is no method that adds or removes a network. Extending a list means constructing a new one.
JSON.stringify produces the CIDR array via NetworkList.toJSON(), and that array can be passed straight back to the constructor. Passing the raw NetworkList.networks buffer works too, and is cheaper, but then the family must be supplied explicitly because the bytes do not record it.
Constructors
|
Constructor |
Modifiers |
Description |
|---|---|---|
|
Builds a list from CIDR records, or adopts an already-packed buffer. |
Properties
|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
|
number |
Bytes per address: 4 for IPv4, 16 for IPv6, per sizeOf(). | |
|
|
number |
Size of NetworkList.networks in bytes. | |
|
|
number |
How many networks the list holds. | |
|
|
Buffer |
The packed records: | |
|
|
number |
Bytes per record: two addresses, so 8 for IPv4 and 32 for IPv6. | |
|
|
The address family every record in this list belongs to. |
Methods
|
Method |
Modifiers |
Description |
|---|---|---|
|
Whether an address falls inside any network in this list. | ||
|
The stored networks as CIDR records. | ||
|
The stored ranges as integer pairs. | ||
|
The CIDR array, so |
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.