@eryldor/cidr
Version:
A javascript library to manipulate CIDR blocks
60 lines (59 loc) • 2.33 kB
TypeScript
interface ICIDRBlockArgs {
addr: number;
prefix: number;
}
export declare class CIDRBlock {
/**
* Construct a [[CIDRBlock]] object from four IP component numbers (eg: a.b.c.d) and a prefix. The network
* address is sanitized by zeroing all the bits after the prefix.
* @throws If any IP component number is invalid or if the prefix is invalid.
*/
static fromNumbers(a: number, b: number, c: number, d: number, prefix: number): CIDRBlock;
/**
* Parse a string into a CIDR block.
* @throws If the stirng is not a valid CIDR block
*/
static fromString(cidr: string): CIDRBlock;
protected static fromNumbersInner(a: number, b: number, c: number, d: number, prefix: number): ICIDRBlockArgs;
protected static fromStringInner(cidr: string): ICIDRBlockArgs;
private static checkIPBoundaries;
private static checkPrefix;
private static networkAddressToString;
readonly networkPrefix: number;
private innerNetworkAddr;
protected constructor(networkAddr: number, prefix: number);
get networkAddress(): string;
/**
* Return the broadcast address of this CIDR block.
*/
get broadcastAddress(): string;
/**
* Return a generator yielding all the IP address this block can contain. It doesn't yield the network address and
* the broadcast address.
*/
ipAddress(): IterableIterator<string>;
/**
* Return the CIDR notation of this block
*/
toString(): string;
/**
* Split the CIDR block into at least `requiredSubnetAmount`.
* @returns The new CIDR blocks generated from the split
* @throws If the block can't be divided by at least `requiredSubnetAmount` or if `requiredSubnetAmount` is negative
*/
split(requiredSubnetAmount: number): CIDRBlock[];
/**
* Return the maximum address index usable with {@link CIDRBlock.getAddress}
*/
get maxAddressIndex(): number;
/**
* Return the i-th address inside this CIDR Block.
*
* Note that `getAddress(0)` is equivalent [[CIDRBlock.networkAddress]],
* `this.getAddress(this.maxAddressIndex)` is equivaent to [[CIDRBlock.broadcastAddress]]
*
* @throws if `i` is not an integer between 0 and [[CIDRBlock.maxAddressIndex]]
*/
getAddress(i: number): string;
}
export {};