Static
abbreviateReturns an abbreviated representation of an IP string.
Examples:
192.168.0.1
(IPv4; same as IPUtil.sanitize)fd12:3456:789a:1::
Inaccurate CIDRs are corrected automatically:
fd12:3456:789a:1:0:0:0:1/64
fd12:3456:789a:1::/64
IP or CIDR string to abbreviate.
Optional
capitalize: booleanWhether to capitalize the output.
Optional
conditionPredicate: ConditionPredicateOptional condition for filtering valid IPs.
Abbreviated string, or null
if:
conditionPredicate
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.
Static
containsStatic
containsStatic
containsStatic
equalsStatic
equalsStatic
equalsProtected
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
isCIDRChecks whether the input is a valid CIDR (either IPv4 or IPv6).
The CIDR string to check.
Optional
mode: "strict"Require strict CIDR formatting if 'strict'
is passed.
Optional
options: StringifyOptionsFormatting options for corrected CIDRs.
Returns true
if valid, false
if invalid, or a normalized CIDR string.
Static
isIPChecks whether the input is a valid IP or CIDR address.
The IP or CIDR string to check.
Optional
allowCidr: boolean | "strict" = falseWhether to allow CIDRs, or require strict CIDR format.
Optional
options: StringifyOptions = {}Formatting options for corrected CIDRs.
Returns true
if valid, false
if invalid, or a normalized CIDR string.
Static
isIPv4Checks whether the input is a valid IPv4 address or IPv4 CIDR.
The IPv4 or IPv4 CIDR string to check.
Optional
allowCidr: boolean | "strict" = falseWhether to allow CIDRs, or require strict CIDR format.
Optional
options: StringifyOptions = {}Formatting options for corrected CIDRs.
Returns true
if valid, false
if invalid, or a normalized CIDR string.
Static
isIPv4CIDRChecks whether the input is a valid IPv4 CIDR.
The IPv4 CIDR string to check.
Optional
mode: "strict"Require strict CIDR formatting if 'strict'
is passed.
Optional
options: StringifyOptionsFormatting options for corrected CIDRs.
Returns true
if valid, false
if invalid, or a normalized CIDR string.
Static
isIPv6Checks whether the input is a valid IPv6 address or IPv6 CIDR.
The IPv6 or IPv6 CIDR string to check.
Optional
allowCidr: boolean | "strict" = falseWhether to allow CIDRs, or require strict CIDR format.
Optional
options: StringifyOptions = {}Formatting options for corrected CIDRs.
Returns true
if valid, false
if invalid, or a normalized CIDR string.
Static
isIPv6CIDRChecks whether the input is a valid IPv6 CIDR.
The IPv6 CIDR string to check.
Optional
mode: "strict"Require strict CIDR formatting if 'strict'
is passed.
Optional
options: StringifyOptionsFormatting options for corrected CIDRs.
Returns true
if valid, false
if invalid, or a normalized CIDR string.
Static
isStatic
isStatic
isStatic
lengthenReturns a fully expanded (lengthened) representation of an IP string.
Examples:
192.168.000.001
fd12:3456:789a:0001:0000:0000:0000:0000
Inaccurate CIDRs are corrected automatically:
fd12:3456:789a:1:0:0:0:1/64
fd12:3456:789a:0001:0000:0000:0000:0000/64
IP or CIDR string to expand.
Optional
capitalize: booleanWhether to capitalize the output.
Optional
conditionPredicate: ConditionPredicateOptional condition for filtering valid IPs.
Expanded string, or null
if:
conditionPredicate
Protected
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.
Static
sanitizeReturns a sanitized representation of an IP string.
Examples:
192.168.0.1
(IPv4; same as IPUtil.abbreviate)fd12:3456:789a:1:0:0:0:0
Inaccurate CIDRs are corrected automatically:
fd12:3456:789a:1::1/64
fd12:3456:789a:1:0:0:0:0/64
IP or CIDR string to sanitize.
Optional
capitalize: booleanWhether to capitalize the output.
Optional
conditionPredicate: ConditionPredicateOptional condition for filtering valid IPs.
Sanitized string, or null
if:
conditionPredicate
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 = {}Protected
Static
validateProtected
Validates whether a string is a valid IP or CIDR address.
allowCidr
is true
, CIDR suffixes are allowed.allowCidr
is 'strict'
, the method returns a normalized CIDR string if the input is valid
but not in canonical form.allowCidr
is false
, CIDR suffixes are disallowed.true
: The input is valid.false
: The input is invalid.string
: A corrected CIDR string (only if allowCidr === 'strict'
and normalization is needed).The IP or CIDR string to validate.
Whether to allow CIDRs, or require strict CIDR format.
Optional
conditionPredicate: ConditionPredicateOptional function to apply additional validation.
Optional
options: StringifyOptionsOutput formatting options (used only if returning a string).
See above.
A utility class that provides static methods for validating and formatting IP and CIDR strings. Unlike the IP class, these methods are stateless and ideal for one-off checks or transformations on varying inputs.