Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on Dec 19, 2023 via pnpm

ipaddr.js 1.8.1

A library for manipulating IPv4 and IPv6 addresses in JavaScript.
Package summary
Share
0
issues
0
licenses
Package created
28 Jul 2011
Version published
31 Jul 2018
Maintainers
1
Total deps
0
Direct deps
0
License
MIT

Issues

0
This package has no issues

Frequently Asked Questions

What does ipaddr.js do?

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.

How do you use ipaddr.js?

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.

Where are the ipaddr.js docs?

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.