NetworkList.(constructor)

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

Signature:

constructor(networks: string[] | Buffer, type?: NetworkType);

Parameters

Parameter

Type

Description

networks

string[] | Buffer

CIDR records, each with an explicit /prefix; or a buffer previously taken from NetworkList.networks

type

NetworkType

(Optional) the address family. Optional only for the array form, where it is detected from the first record; required for the buffer form, since the bytes do not say.

Exceptions

TypeError if a record's address is invalid, if the records disagree on family, or — for the buffer form — if type was omitted or the buffer is empty or not a whole number of records.

RangeError if a record has no /prefix. A bare address is rejected, so a single host is 10.0.0.1/32.

Remarks

The array form sorts and deduplicates by range, so the resulting NetworkList.length may be lower than the number of records you passed. The buffer form trusts the bytes and copies nothing — it keeps a reference, so mutating that buffer afterwards corrupts the list.

Example

const list = new NetworkList(['10.0.0.0/8', '192.168.0.0/16']);

// Cheap round trip: keep the bytes, restate the family.
const same = new NetworkList(list.networks, list.type);

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