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

(constructor)(networks, type)

Builds a list from CIDR records, or adopts an already-packed buffer.

Properties

Property

Modifiers

Type

Description

addressSize

readonly

number

Bytes per address: 4 for IPv4, 16 for IPv6, per sizeOf().

bytesLength

readonly

number

Size of NetworkList.networks in bytes.

length

readonly

number

How many networks the list holds.

networks

readonly

Buffer

The packed records: [start, end] address pairs, little-endian, ascending.

recordSize

readonly

number

Bytes per record: two addresses, so 8 for IPv4 and 32 for IPv6.

type

readonly

NetworkType

The address family every record in this list belongs to.

Methods

Method

Modifiers

Description

includes(ip)

Whether an address falls inside any network in this list.

toArray(canonical)

The stored networks as CIDR records.

toIntArray()

The stored ranges as integer pairs.

toJSON()

The CIDR array, so JSON.stringify on this object yields the network list.

Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.