ipaddr.js
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Ipaddr.js is a compact and versatile JavaScript library dedicated to manipulating IPv4 and IPv6 addresses. Its functionality is diverse: it allows one to verify and parse string representations of IP addresses, match them against specified CIDR ranges or range lists, identify if they fall into specific reserved ranges (including loopback and private ranges), and switch between IPv4 and IPv4-mapped IPv6 addresses.
To use the ipaddr.js package, firstly it needs to be installed into your project using npm or bower:
npm install ipaddr.js
or
bower install ipaddr.js
Once installed, use require to include it in your JavaScript file:
const ipaddr = require('ipaddr.js');
The ipaddr.js offers global methods including ipaddr.isValid
, ipaddr.parse
, and ipaddr.process
. Example usage:
// Validating string as valid IP
console.log(ipaddr.isValid('2001:db8::1')); // returns true
console.log(ipaddr.isValid('500.500.500.500')); // returns false
// Parsing IP address
var addr = ipaddr.parse('2001:db8::1');
console.log(addr); // returns IPv6 object
// Processing IP address (particular use case)
var processed = ipaddr.process('::ffff:192.0.2.128');
console.log(processed); // returns IPv4 object
Another extensive part of the API is the ipaddr.IPv6 and ipaddr.IPv4 classes, where you can work with an object representing the IP address and call various methods on these objects.
The ipaddr.js documentation can be found in the README file on the GitHub repository. The readme includes installation instructions, code usage examples, and descriptions of the API methods.