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
readonlyvalue:bigint
Defined in: IPAddress.ts:28
Integer representation of the IP address.
Inherited from
BIT_LENGTH
staticBIT_LENGTH:number=32
Defined in: IPv4.ts:31
Bit length of IPv4 addresses.
REGEX
staticREGEX: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
binary()
binary():
Uint8Array
Defined in: IPv4.ts:92
Returns the 4 octets of the IPv4 address.
Returns
Overrides
equals()
equals(
other):boolean
Defined in: IPAddress.ts:67
Checks if the given address is equal to this address.
Parameters
other
Address to compare.
Returns
boolean
Inherited from
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
ip.offset(1) // Returns the next IP address.ip.offset(-1) // Returns the previous IP address.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
toString()
toString():
string
Defined in: IPv4.ts:104
Returns the IP address as a string in dotted-decimal notation.
Returns
string
Overrides
fromBinary()
staticfromBinary(octets):IPv4
Defined in: IPv4.ts:62
Creates an IPv4 address instance from octets.
Parameters
octets
Typed array of 4 octets.
Returns
IPv4
Throws
RangeError If the number of octets is not 4.
fromString()
staticfromString(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.