Type Alias StrictCIDR

StrictCIDR: "strict"

The strict CIDR validation mode ensures that CIDR addresses have a matching prefix for the specified bit length. If a CIDR string is technically valid but the prefix does not align with the given bit length, it will be corrected and returned as a string.

For example, 192.168.0.1/24 is considered inaccurate because the prefix should be 192.168.0.0 for a /24 subnet. In strict mode, this input is not rejected—instead, it is interpreted as valid and automatically corrected.

When strict mode is off, IPUtil.isIP('192.168.0.1/24', true) returns true. When strict mode is on, the method returns the corrected CIDR string:

// allowCidr: false or undefined
console.log(IPUtil.isIP('192.168.0.1')); // true
console.log(IPUtil.isIP('192.168.0.1/24')); // false

// allowCidr: true
console.log(IPUtil.isIP('192.168.0.1', true)); // true
console.log(IPUtil.isIP('192.168.0.1/24', true)); // true
console.log(IPUtil.isIP('192.168.0.0/24', true)); // true

// allowCidr: 'strict'
console.log(IPUtil.isIP('192.168.0.1', 'strict')); // true (same as allowCidr: true)
console.log(IPUtil.isIP('192.168.0.1/24', 'strict')); // "192.168.0.0/24"
console.log(IPUtil.isIP('192.168.0.0/24', 'strict')); // true