Interface IPOptions

Combined options for parsing and formatting IP addresses.

This interface is an amalgamation of both ParseOptions and StringifyOptions, allowing configuration of both input parsing behavior and output formatting style.

interface IPOptions {
    capitalize?: boolean;
    conditionPredicate?: ((version: 4 | 6, isCidr: boolean) => boolean);
    format?: "default" | "short" | "long";
    mode?: "short" | "long";
    suppressFullLengthCidr?: boolean;
}

Hierarchy (view full)

Properties

capitalize?: boolean

Whether to convert output to uppercase (applies to IPv6 hex segments).

conditionPredicate?: ((version: 4 | 6, isCidr: boolean) => boolean)

Optional callback to filter IP addresses by version or CIDR status.

Type declaration

    • (version, isCidr): boolean
    • Parameters

      • version: 4 | 6

        IP version (4 for IPv4, 6 for IPv6).

      • isCidr: boolean

        Whether the address includes a CIDR suffix.

      Returns boolean

      true to accept the address, false to reject.

format?: "default" | "short" | "long"

Address formatting style:

  • 'default' (default):

    • IPv4 returns sanitized form (e.g., 192.168.0.1)
    • IPv6 returns condensed form without aggressive shortening (e.g., fd12:3456:789a:1:0:0:0:0)
  • 'short': Aggressive shortening for IPv6 using :: per RFC 5952.

    • IPv4 unchanged from default.
  • 'long': Full zero-padded form.

    • IPv4: 192.168.000.001
    • IPv6: fd12:3456:789a:0001:0000:0000:0000:0000
mode?: "short" | "long"

Use format instead.

suppressFullLengthCidr?: boolean

Whether to suppress explicit full-length CIDRs (i.e., /32 for IPv4 and /128 for IPv6).

When true, these CIDRs are treated as plain host addresses rather than as CIDR ranges. (Default: true)

For example, if the input string is "192.168.0.1/32" and this option is true, the bit length is suppressed and the address is parsed as "192.168.0.1".