JSPM

  • Created
  • Published
  • Downloads 152737
  • Score
    100M100P100Q172281F
  • License MIT

Module for working with CIDR (v4, v6)

Package Exports

  • ip-cidr

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ip-cidr) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Install

npm install ip-cidr

About

Module for working with CIDR (v4, v6). Based on ip-address.

Example

const IPCIDR = require("ip-cidr");
const cidr = new IPCIDR("50.165.190.0/23"); 

if(!cidr.isValid()) {
  // do something 
}

// get start ip as string
cidr.start(); 

// get end ip as big integer
cidr.end({ type: "bigInteger" }); 

// do something with each element of CIDR range  
cidr.loop(ip => console.log(ip), { type: "addressObject" });

// get an array of all ip in CIDR range as big integer;
cidr.toArray({ type: "bigInteger" }); 

// get an array of start and end ip as string [startIpAsString, endIpAsString]
cidr.toRange(); 

Client side

Load /dist/ip-cidr.js as script and get the library in window.IPCIDR

API

.formatIP(address, [options])

returns "ip-address" module object in the necessary format
options are the same in all of the library functions.

.start([options])

get start ip

.end([options])

get end ip

.toString()

get string cidr as "50.165.190.0/23"

.toRange([options])

get an array of start and end ip [startIp, endIp]

.toObject([options])

get an object of start and end ip {start: startIp, end: endIp}

.toArray([options], [results])

get an array of all ip in CIDR range
you can get an information by chunks using options.from and options.limit
this options might be an integer or a big integer("jsbn" instance)
you can pass the second argument "results" (object) to get all chunk pagination information

.loop(fn, [options], [results])

run fn for every element of CIDR range
you can use the same chunk options as in .toArray