Class IPAddress<Type>

A Respresentation of an IP Address

Example

import { network } from "@rjweb/utils"

const ip = new network.IPAddress('127.1')
ip.isIPv4() // true

ip.long() // 127.0.0.1
ip.short() // 127.1

Since

1.7.0

Supports

nodejs, browser

Type Parameters

  • Type extends 4 | 6 = 4 | 6

Constructors

  • Create a new IP Address

    Type Parameters

    • Type extends 4 | 6 = 4 | 6

    Parameters

    • ip: string | number | bigint | Uint8Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | IPAddress<4 | 6>
    • Optional type: Type

    Returns IPAddress<Type>

    Example

    import { network } from "@rjweb/utils"

    const ip = new network.IPAddress('127.1')
    ip.type // 4
    ip.full() // 127.0.0.1
    ip.short() // 127.1

    Since

    1.7.0

    Supports

    nodejs, browser

Properties

rawData: Type extends 4
    ? Type<Type> extends 6
        ? Uint8Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike>
        : Uint8Array<ArrayBufferLike>
    : Uint16Array<ArrayBufferLike>

The Raw Byte Data of the IP

Since

1.7.0

type: Type

Methods

  • Get the Hexadecimal Representation of this IP

    Returns string

    Since

    1.12.25

  • Get the Integer Representation of this IP

    Returns Type extends 4
        ? Type<Type> extends 6
            ? number | bigint
            : number
        : bigint

    Since

    1.8.6

  • Get the Long representation of this IP

    Returns string

    Since

    1.7.0

  • Get the Reverse Representation of this IP for PTR Records

    Returns string

    Since

    1.12.25

  • Get the Short representation of this IP

    Returns string

    Since

    1.7.0

  • Get the Usual representation of this IPs Version

    Returns .long() for v4 and .short() for v6

    Returns string

    Since

    1.8.5