ipToInt() function
Converts an address to the unsigned bigint this package compares with.
Signature:
export declare function ipToInt(ip: string, type?: NetworkType): bigint;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
ip |
string |
the address to convert |
|
type |
(Optional) the family, if you already know it; omit to have it detected |
Returns:
bigint
The address as a single integer — 32 bits of range for IPv4, 128 for IPv6.
Exceptions
TypeError if the address is not valid, or if type disagrees with it.
Remarks
The bridge between text and every numeric operation here: ranges, sorting and binary search all work on these values. Because the two families are converted into the same unsigned space and IPv4 occupies only its low 32 bits, values from different families must never be compared — which is why Networks keeps them apart.
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.