Protected
constructorProtected
Private constructor. Use IP.newFromText or IP.newFromRange to create a new instance.
An object containing internal CIDR information.
Protected
Readonly
bitProtected
Readonly
firstProtected
Readonly
isProtected
Readonly
lastReturns the IP version as a number.
The IP version: 4
for IPv4 or 6
for IPv6.
Returns the stringified form of this IP or CIDR block in an abbreviated format.
This is a shorthand method of stringify with the mode
option set to 'short'
.
Optional
capitalize: boolean = falseWhether to capitalize the output.
A properly formatted string representation of the IP or CIDR.
Checks whether the CIDR range associated with this instance contains the specified IP address.
The target IP address to check.
true
if the CIDR range contains ipStr
, false
if not, or null
if ipStr
is invalid.
Checks whether the CIDR range associated with this instance contains all of the IP addresses in the array.
An array of IP or CIDR strings or IP instances to test.
true
if all IPs are contained, false
if any are not, or null
if
ipArr
is not an array or an empty array.
Checks whether the CIDR range associated with this instance contains any of the IP addresses in the array.
An array of IP or CIDR strings or IP instances to test.
The index of the first match in ipArr
, or -1
if none match.
Checks whether the IP address associated with this intance is equal to a given IP address.
The IP address to compare.
true
if the IPs are equal, false
if not, or null
if ipStr
is invalid.
Checks whether the IP address associated with this intance is equal to all addresses in a given array.
An array of IP or CIDR strings or IP instances to compare against.
true
if all addresses are equal to this IP instance, false
otherwise, or
null
if ipArr
is not an array or an empty array.
Checks whether the IP address associated with this intance is equal to any address in a given array.
An array of IP or CIDR strings or IP instances to check against.
The index of the first match in ipArr
, or -1
if none match.
Gets the bit length of the current instance.
This always returns a number between 0-32
for IPv4 and 0-128
for IPv6.
To check whether the current instance represents a CIDR address, use IP.isCIDR.
The bit length as a number.
Gets a copy of the internal CIDR-related properties.
An object containing first
, last
, bitLen
, and isCidr
.
Gets range information of the IP instance.
Optional
getInstance: falseWhether to get the start and end IP addresses as IP instances.
Optional
options: StringifyOptionsOptional formatting options for the cidr
, first
,
and last
properties.
Gets range information of the IP instance.
Whether to get the start and end IP addresses as IP instances.
Optional
options: StringifyOptionsOptional formatting options for the cidr
property.
Checks whether the IP address associated with this instance is within all CIDR ranges in the array.
An array of CIDR strings or IP instances to check against.
true
if the IP is within all CIDRs, false
if not, or null
if cidrArr
is
not an array or an empty array.
Checks whether the IP address associated with this instance is within any of the CIDR ranges in the array.
An array of CIDR strings or IP instances to check against.
The index of the first matching CIDR in the array, or -1
if none match.
Checks whether the IP address associated with this instance is within the CIDR range of another.
The CIDR string or IP instance representing the range.
A boolean indicating whether the IP address is within the CIDR range, or
null
if cidrStr
is invalid.
Returns the stringified form of this IP or CIDR block in a lengthened format.
This is a shorthand method of stringify with the mode
option set to 'long'
.
Optional
capitalize: boolean = falseWhether to capitalize the output.
A properly formatted string representation of the IP or CIDR.
Returns the stringified form of this IP or CIDR block in a sanitized format.
This is a shorthand method of stringify with the mode option unset.
Optional
capitalize: boolean = falseWhether to capitalize the output.
A properly formatted string representation of the IP or CIDR.
Returns the stringified form of this IP or CIDR block.
Optional
options: StringifyOptions = {}Optional formatting options. If omitted, a default "sanitized" format will be used.
A properly formatted string representation of the IP or CIDR.
Note: If the instance was initialized from an imprecise CIDR string, the output will reflect the corrected internal format.
const ip = IP.newFromText('fd12:3456:789a:1::1/64');
ip.stringify(); // fd12:3456:789a:1:0:0:0:0/64
Alias for IP.stringify with default options.
A stringified representation of the IP.
Protected
Static
checkProtected
Checks if two IP addresses are equal.
Range object of the first IP.
IP or CIDR string, or IP instance.
null
if the second input is invalid.
Static
cleanReturns a trimmed string with all Unicode bidirectional characters removed.
Unicode bidirectional characters are special invisible characters that can slip into cut-and-pasted strings, which are shown as red dots in WikiEditor. They can cause issues when parsing IP addresses.
Protected
Static
compareProtected
Compares two IP address ranges to check for inclusion.
Range object of the first IP.
IP string or IP instance to compare against.
Use <
if ip2
should contain ip1
, or >
if ip1
should contain ip2
.
null
if ip2
is not a valid IP address.
Protected
Static
getProtected
Parses an IP string or instance into a range object.
An IP/CIDR string or IP instance.
Range object, or null
if the input is not a valid IP.
Static
newInitializes an IP instance from a string and a range (aka. a bit length).
An IP- or CIDR-representing string. If a CIDR string is passed, the /XX
part
will be overridden by range
.
The desired CIDR bit length (0–32 for IPv4, 0–128 for IPv6).
A new IP
instance if parsing succeeds, or null
if the input or range is invalid.
Static
newProtected
Static
parseProtected
Parses a string potentially representing an IP or CIDR address.
The string to parse.
Optional
bitLen: numberOptional bit length for CIDR parsing.
A parsed object, or null
if:
ipStr
is not a string.Protected
Static
parseProtected
Parses and stringifies an IP string with optional filtering.
IP or CIDR string to parse.
Options for formatting.
Optional
conditionPredicate: ConditionPredicateA predicate to filter addresses by version and CIDR.
null
if:
conditionPredicate
Protected
Static
parseProtected
Returns the first and last IPs in the given range.
Decimal parts of the IP address.
Optional CIDR bit length.
Protected
Static
stringifyProtected
Converts an array of decimal IP parts into a string.
Array of decimal parts.
Suffix to append (e.g., /24
).
Optional
options: StringifyOptions = {}
The IP class. Unlike the static IPUtil class, this class provides several instance methods that can be used to perform validations on the same IP or CIDR address multiple times.
To initialize a new instance, use IP.newFromText or IP.newFromRange: