ip-address

raw JSON →
10.1.0 verified Sat Apr 25 auth: no javascript

A JavaScript/TypeScript library for parsing, validating, and manipulating IPv4 and IPv6 addresses. Current stable version is 10.1.0, released with breaking changes from v9 (native BigInt support). Works in Node.js (>=12) and browsers via bundlers. Key differentiators: built-in Teredo inspection, subnet calculations, special property detection, and ~1,600 test cases. Ships TypeScript definitions.

error TypeError: Address6 is not a constructor
cause Using incorrect import path or mixing default and named exports
fix
Use: import { Address6 } from 'ip-address' or const { Address6 } = require('ip-address')
error Error: ip-address requires BigInt support
cause Runtime environment does not support native BigInt
fix
Upgrade Node.js to >=10.4 or use older ip-address v9.x
error Module not found: Can't resolve 'ip-address'
cause Package not installed or import path is wrong
fix
Run: npm install ip-address
breaking fromBigInteger() renamed to fromBigInt(); bigInteger() renamed to bigInt()
fix Use fromBigInt() and bigInt() instead; these now return native BigInt values.
deprecated Using CommonJS require() may be deprecated in future versions
fix Switch to ESM import syntax.
gotcha The library uses native BigInt; ensure your runtime supports BigInt (Node.js >=10.4, modern browsers).
fix If you need older JS engine support, stay on v9.x.
npm install ip-address
yarn add ip-address
pnpm add ip-address

Basic usage of Address4 and Address6 showing validation, formatting, Teredo inspection, and subnet calculation.

import { Address4, Address6 } from 'ip-address';

// IPv4 example
const ipv4 = new Address4('192.168.1.1');
console.log(ipv4.isValid()); // true
console.log(ipv4.correctForm()); // '192.168.1.1'
console.log(ipv4.subnetMask); // 32

// IPv6 example
const ipv6 = new Address6('2001:0:ce49:7601:e866:efff:62c3:fffe');
console.log(ipv6.isValid()); // true
console.log(ipv6.canonicalForm()); // '2001:0:ce49:7601:e866:efff:62c3:fffe'

// Inspect Teredo
const teredo = ipv6.inspectTeredo();
console.log(teredo.client4); // '157.60.0.1'

// Subnet calculation
const subnet = ipv6.subnet(64);
console.log(subnet.canonicalForm()); // '2001:0:ce49:7601::/64'