@xstd/ipv4
v1.0.1
Published
IPv4 parser and serializer
Readme
@xstd/ipv4
IPv4 parser and serializer.
Example
const ipv4 = new IPv4('192.168.1.1');
console.log(ipv4.blocks); // [192, 168, 1, 1]
console.log(ipv4.toString()); // '192.168.1.1'📦 Installation
yarn add @xstd/ipv4
# or
npm install @xstd/ipv4 --save📜 Documentation
type IPv4Source = string | IPv4Blocks | Iterable<number> | IPv4;
type IPv4Blocks = readonly [number, number, number, number];
/**
* Represents an IPv4 address.
*
* - [Wikipedia](https://en.wikipedia.org/wiki/IPv4)
* - [IPv4address](https://datatracker.ietf.org/doc/html/rfc3986#appendix-A)
*/
declare class IPv4 {
/**
* Returns `true` if `input` can be parsed into a valid IPv4.
*/
static canParse(input: string): boolean;
/**
* Returns a `IPv4` if `input` can be parsed a into valid IPv4, else it returns `null`.
*/
static parse(input: string): IPv4 | null;
/**
* If `input` is an `IPv4`, returns it, else returns a new `IPv4` instance based on `input`.
*/
static of(input: IPv4Source): IPv4;
/**
* Constructs a new IPv4.
*
* @throws {Error} if the `input` is not a valid IPv4.
*
*/
constructor(input: IPv4Source);
/**
* Returns the IPv4 address as an array of four octets.
*/
get blocks(): IPv4Blocks;
/**
* Converts the IPv4 address into a string.
*/
toString(): string;
}