Function convertIpv4

  • Converts an ipv4 address to or from uint32 number.

    • If the value is a string, it will be parsed to array of octets and passed further for conversion to number (uint32).
    • If the value is an array, it will be passed further for conversion to number (uint32).
    • If the value is a number, it will be parsed to quad-dot format.
    • Returns a string or number depending on the type of passed argument.
    • It will throw an error if the octet numbers are not valid.

    Returns

    string or number reflecting the input value in its counter format.

    Example

    convertIpv4("192.168.1.1");         // "3232235777"
    convertIpv4(3232235777); // "192.168.1.1"
    convertIpv4(1); // "1.0.0.0"
    convertIpv4("1"); // Throws an error for invalid IPv4 address

    Parameters

    • ipv4: number | `${number}.${number}.${number}.${number}`

      The value to convert (string, number, or array of numbers).

    Returns string | number

Generated using TypeDoc