@dnspect/ip-address-ts
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

@dnspect/ip-address-ts

npm   Run npm tests   Lint  

IP addresses library in TypeScript. It defines an Address interface with Address4 and Address6 implementations.

Building on the Address types, the package also defines Prefix representing an IP network or an address block.

Features

  • IPv4 (Address4)
  • IPv6 (Address6)
  • Network Prefix (Prefix)
  • Binary representation in bytes and 16-bit groups
  • Text notations formatting and parsing
  • ".arpa" representations formatting and parsing

Install

Add this package to your package.json by running this in the root of your project's directory:

npm install @dnspect/ip-address-ts

Usage

This package is designed to have no dependency on specific JavaScript runtime.

import { Address4, Address6, Prefix } from "@dnspect/ip-address-ts";

// Parses from text notation
const loopback4 = Address4.parse("127.0.0.1");
// Parses from in-addr.arpa representation
const loopback4 = Address4.fromArpa("1.0.0.127.in-addr.arpa.");

// Parses from text notation
const loopback6 = Address6.parse("::1");
// Parses from ip6.arpa representation
const loopback6 = Address6.fromArpa("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa");

// Defines the documentation range of IPv6
const docRange = Prefix.parse("2001:db8::1/32");

Package Sidebar

Install

npm i @dnspect/ip-address-ts

Weekly Downloads

14

Version

0.2.1

License

MIT

Unpacked Size

183 kB

Total Files

43

Last publish

Collaborators

  • hunts