cidr-block
Version:
ipv4 and ipv6 address and cidr range utilities
110 lines (109 loc) • 3.1 kB
TypeScript
import { Ipv6Literal, Ipv6Representable } from './types';
/**
* Representation of an IPv6 address. Provides various utilities methods like equality
* checking.
*
* @remarks
* Avoid direct instantiation; use {@link ipv6.address} instead.
*/
export declare class Ipv6Address {
private _address;
constructor(address: Ipv6Literal);
/**
* The address as a bigint
*
* @remarks
* Because the representation of an IPv6 address is too large to fit into a typical
* JavaScript integer, a
* {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt}
* is used instead.
*/
get address(): bigint;
/**
* Returns the string representation of the address
*/
toString(): string;
/**
* Compares if two IPv6 addresses are the same.
*
* @example
* ```typescript
* import { ipv6 as ip } from 'cidr-block'
*
* function isLoopback(address: Ipv6Representable) {
* return ip.address(address).equals('::1')
* }
*
* @public
* @param otherIpAddress the other Ipv6 address to compare
* @returns if the other IP address is the same
* ```
*/
equals(otherIpAddress: Ipv6Representable): boolean;
/**
* Calculates the next logical IPv6 address.
*
* @example
* ```typescript
* import { ipv6 as ip } from 'cidr-block'
*
* const myIp = ip.address('2001:0db8::ac10')
* myIp.nextIp() // ==> '2001:0db8::ac11'
* ```
*/
nextIp(): Ipv6Address;
/**
* Calculates the previous logical IPv6 address.
*
* @example
* ```typescript
* import { ipv6 as ip } from 'cidr-block'
*
* const myIp = ip.address('2001:0db8::ac10')
* myIp.previousIp() // ==> '2001:0db8::ac09'
* ```
*/
previousIp(): Ipv6Address;
}
/**
* Convenience function for creating an IPv6 address instance.
*
* @remarks
* In general, you should use this function instead of instantiating an Ipv6Address
* object directly.
*
* @example
*
* ```typescript
* import { ipv6 as ip } from 'cidr-block'
*
* const localhost = ip.address('::1')
* ```
*
* @see {@link Ipv6Address}
*
* @param ip string representation of the IPv6 address
* @returns an instance of Ipv6Address
*/
export declare function address(ip: Ipv6Literal): Ipv6Address;
/**
* Converts the string representation of an IPv6 address to a bigint.
*
* @see {@link Ipv6Address}
*
* @public
* @param ip string representation of the IPv6 address
* @returns an instance of Ipv6Address
*/
export declare function stringToNum(address: string): bigint;
/**
* Converts the numerical representation of an IPv6 address to its string representation.
*
* @see This method is the inverse of {@link ipv6.stringToNum}
* @throws {@link InvalidIpAddressError}
*
* @public
* @param ip IPv6 address as a number
* @returns string representation of the address
*/
export declare function numToString(num: bigint): string;