Quick start with ipaddr.js
mainImport the library and use the global API to validate addresses, parse them into objects, or parse CIDR notation.
Note: ipaddr.parse() and ipaddr.parseCIDR() will throw an error if the input is invalid. Use ipaddr.isValid() or ipaddr.isValidCIDR() to check validity without throwing.
const ipaddr = require('ipaddr.js');
ipaddr.isValid('192.168.1.1'); // => true
ipaddr.isValid('2001:db8::1'); // => true
ipaddr.isValid('not an address'); // => false
const addr = ipaddr.parse('2001:db8::1');
addr.kind(); // => 'ipv6'
addr.toString(); // => '2001:db8::1'
const [network, prefix] = ipaddr.parseCIDR('10.0.0.0/8');
network.toString(); // => '10.0.0.0'
prefix; // => 8