Skip to content

Class: IPv4

Defined in: IPv4.ts:22

Represents an Internet Protocol version 4 (IPv4) address.

Extends

Constructors

Constructor

new IPv4(value): IPv4

Defined in: IPv4.ts:39

Creates a new IPv4 address instance.

Parameters

value

bigint

32-bit unsigned integer.

Returns

IPv4

Throws

TypeError If the value is not a 32-bit unsigned integer.

Overrides

IPAddress.constructor

Constructor

new IPv4(value): IPv4

Defined in: IPv4.ts:47

Creates a new IPv4 address instance.

Parameters

value

number

32-bit unsigned number.

Returns

IPv4

Throws

TypeError If the value is not a 32-bit unsigned integer.

Overrides

IPAddress.constructor

Properties

value

readonly value: bigint

Defined in: IPAddress.ts:28

Integer representation of the IP address.

Inherited from

IPAddress.value


BIT_LENGTH

static BIT_LENGTH: number = 32

Defined in: IPv4.ts:31

Bit length of IPv4 addresses.


REGEX

static REGEX: RegExp

Defined in: IPv4.ts:26

Regular expression for testing IPv4 addresses in dotted-decimal string notation.

Methods

[toPrimitive]()

[toPrimitive](hint): string | bigint

Defined in: IPAddress.ts:76

Returns the IP address as a bigint or string primitive.

Parameters

hint

Preferred primitive type.

"string" | "number" | "default"

Returns

string | bigint

Inherited from

IPAddress.[toPrimitive]


binary()

binary(): Uint8Array

Defined in: IPv4.ts:92

Returns the 4 octets of the IPv4 address.

Returns

Uint8Array

Overrides

IPAddress.binary


equals()

equals(other): boolean

Defined in: IPAddress.ts:67

Checks if the given address is equal to this address.

Parameters

other

IPAddress

Address to compare.

Returns

boolean

Inherited from

IPAddress.equals


offset()

offset(offset): IPv4

Defined in: IPv4.ts:108

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

Parameters

offset

Number of steps to offset, positive or negative.

number | bigint

Returns

IPv4

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.

Overrides

IPAddress.offset


toString()

toString(): string

Defined in: IPv4.ts:104

Returns the IP address as a string in dotted-decimal notation.

Returns

string

Overrides

IPAddress.toString


fromBinary()

static fromBinary(octets): IPv4

Defined in: IPv4.ts:62

Creates an IPv4 address instance from octets.

Parameters

octets

Uint8Array

Typed array of 4 octets.

Returns

IPv4

Throws

RangeError If the number of octets is not 4.


fromString()

static fromString(ip): IPv4

Defined in: IPv4.ts:81

Creates an IPv4 address instance from a string.

Parameters

ip

string

String representation of an IPv4 address.

Returns

IPv4

Throws

RangeError If the string is not a valid IPv4 address.

Overrides

IPAddress.fromString

Released under the LGPL-3.0 licence.