Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace ipv4

Index

Type aliases

Ipv4Literal: string | number

Type that indicates a literal string or number value that represents an IPv4 address

Ipv4Representable: Ipv4Address | Ipv4Literal

Type that indicates either a literal value or an address instance that is an IPv4

Variables

MAX: number = ...

The numerical maximum size an IPv4 address can be

Functions

  • Convenience function for creating an IPv4 address instance.

    remarks

    In general, you should use this function instead of instantiating an Ipv4Address object directly.

    example
    import { ipv4 as ip } from 'cidr-block'

    const localhost = ip.address('127.0.0.1')
    see

    Ipv4Address

    Parameters

    • ip: Ipv4Literal

      string representation of the IPv4 address

    Returns Ipv4Address

    an instance of Ipv4Address

  • Convenience function for creating an IPv4 cidr range instance.

    remarks

    In general, you should use this function instead of instantiating an Ipv4Cidr object directly. While there is nothing wrong with direct instantiation, convenience methods like these are meant to help reduce the footprint of your code and increase readability.

    example
    import { ipv4 as ip } from 'cidr-block'

    const vpcCidrRange = ip.cidr('10.0.0.0/16')
    see

    Ipv4Cidr

    Parameters

    • cidrRange: string

      string representation of the cidr range

    Returns Ipv4Cidr

    an instance of Ipv4Cidr

  • numToString(ip: number): string
  • Converts the numerical representation of an IPv4 address to its string representation.

    example
    import * as cidr from 'cidr-block'

    cidr.ipv4.numToString(0) === '0.0.0.0' // ==> true
    cidr.ipv4.numToString(65_280) === '0.0.255.0' // ==> true
    cidr.ipv4.numToString(4_294_967_295) === '255.255.255.255' // ==> true
    see

    This method is the inverse of ipv4.stringToNum

    throws

    InvalidIpAddressError

    Parameters

    • ip: number

      IPv4 address as a number

    Returns string

    string representation of the address

  • stringToNum(address: string): number
  • Converts the string representation of an IPv4 address to a number.

    example
    import * as cidr from 'cidr-block'

    cidr.ipv4.stringToNum('255.255.255.255') === 4_294_967_295 // ==> true
    cidr.ipv4.stringToNum('0.0.0.255') === 255 // ==> true
    see

    This method is the inverse of ipv4.numToString

    throws

    InvalidIpAddressError

    Parameters

    • address: string

      IPv4 address represented as a string

    Returns number

    numerical number representation of the address

Generated using TypeDoc