• Check if an IP is valid

    Parameters

    • ip: string
    • type: "v4" | "v6" | "v6 | v4" = 'v6 | v4'

    Returns "v4" | "v6" | false

    IP Type or false if failed

    Example

    import { network } from "@rjweb/utils"

    network.isIP('127.0.0.1', 'v4') // 'v4'
    network.isIP('127.0.0.1', 'v6') // false
    network.isIP('::1', 'v4') // false
    network.isIP('::1', 'v6') // 'v6'
    network.isIP('127.0.0.1', 'v6 | v4') // 'v4'
    network.isIP('1.1') // 'v4'

    Since

    1.1.0

    Supports

    nodejs, browser