Skip to content

Abstract Class: IPAddress ​

Defined in: IPAddress.ts:24

Sealed

Represents an Internet Protocol (IP) address.

Extended by ​

Properties ​

value ​

readonly value: bigint

Defined in: IPAddress.ts:28

Integer representation of the IP address.

Methods ​

[toPrimitive]() ​

[toPrimitive](hint): string | bigint

Defined in: IPAddress.ts:77

Returns the IP address as a bigint or string primitive.

Parameters ​

hint ​

"string" | "number" | "default"

Preferred primitive type.

Returns ​

string | bigint


binary() ​

abstract binary(): ArrayBufferView

Defined in: IPAddress.ts:61

Returns the binary representation of the IP address.

Returns ​

ArrayBufferView


equals() ​

equals(other): boolean

Defined in: IPAddress.ts:68

Checks if the given address is equal to this address.

Parameters ​

other ​

IPAddress

Address to compare.

Returns ​

boolean


offset() ​

abstract offset(offset): IPAddress

Defined in: IPAddress.ts:101

Returns a new IP address offset by the given amount from this address.

Parameters ​

offset ​

number | bigint

Number of steps to offset, positive or negative.

Returns ​

IPAddress

Examples ​

ts
ip.offset(1) // Returns the next IP address.
ts
ip.offset(-1) // Returns the previous IP address.
ts
IPAddress.fromString("203.0.113.42").offset(-18) // Returns 203.0.113.24.

Throws ​

TypeError If the resulting address is outside the IP address family range.


toString() ​

abstract toString(): string

Defined in: IPAddress.ts:89

Returns the IP address as a string.

Returns ​

string


fromString() ​

static fromString(ip, resolveMapped?): IP

Defined in: IPAddress.ts:47

Creates an IP address from a string.

Parameters ​

ip ​

string

String representation of the IP address.

resolveMapped? ​

boolean = false

Whether to resolve IPv4-mapped IPv6 addresses (see IPv6.hasMappedIPv4).

Returns ​

IP

Throws ​

RangeError If the string is not a valid IPv4 or IPv6 address.

Released under the LGPL-3.0 licence.