getType() function
Determines an address's family, or verifies the one you claim it has.
Signature:
export declare function getType(ip: string, type?: NetworkType): NetworkType;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
ip |
string |
the address to inspect |
|
type |
(Optional) the family you expect; omit to have it detected |
Returns:
The family the address belongs to. When type was supplied and matches, that same value comes back.
Exceptions
TypeError if ip is empty, if it contains neither : nor . so no family can be detected, if type is not a NetworkType, or if type disagrees with the address.
Remarks
Detection is by punctuation only — a : means IPv6 and a . means IPv4, with : winning, which is what classifies the IPv4-mapped form ::ffff:1.2.3.4 as IPv6. It does not check that the address is well formed, so getType('1.2.3.999') returns IPV4 quite happily; use validate() or isValid() for that.
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.