UNPKG

cidr-block

Version:

ipv4 and ipv6 address and cidr range utilities

69 lines (68 loc) 1.92 kB
import { Ipv4Representable } from './types'; import { Ipv4Address } from './ipv4-address'; export declare class Ipv4Cidr { private _ipAddress; private _maskSize; constructor(cidrRange: string); /** * The size of the cidr netmask (the number after the slash in cidr notation) */ get maskSize(): number; /** * Number of IP addresses within the cidr range */ get allocatableIpCount(): number; /** * The actual IPv4 netmask address */ get netmask(): Ipv4Address; /** * The first IPv4 address that is usable within the given cidr range */ get firstUsableIp(): Ipv4Address; /** * The last IPv4 address that is usable within the given cidr range */ get lastUsableIp(): Ipv4Address; private get addressLength(); /** * @returns string representation of the cidr range */ toString(): string; /** * @returns the next consecutive cidr block */ nextBlock(ofSize?: number): Ipv4Cidr; /** * @returns the previous cidr block */ previousBlock(): Ipv4Cidr; /** * @returns if the given IPv4 address is within the cidr range */ includes(address: Ipv4Representable): boolean; } /** * 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 * * ```typescript * import { ipv4 as ip } from 'cidr-block' * * const vpcCidrRange = ip.cidr('10.0.0.0/16') * ``` * * @see {@link Ipv4Cidr} * * @param cidrRange string representation of the cidr range * @returns an instance of Ipv4Cidr */ export declare function cidr(cidrRange: string): Ipv4Cidr;