npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ip-cidr

v4.0.2

Published

Module for working with CIDR (v4, v6)

Downloads

454,820

Readme

Install

npm install ip-cidr

About

Module for working with CIDR (v4, v6). Based on ip-address. Since v4+ using javascript BigInt for big numbers handling.

Example

import IPCIDR from 'ip-cidr';
const address = "50.165.190.0/23";

if(!IPCIDR.isValidCIDR(address)) {
  return;
}

const cidr = new IPCIDR(address); 

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

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

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

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

// get an array by chunks using from/limit
cidr.toArray({ from: 1, limit: 2n });

// get an array by chunks using from/to
cidr.toArray({ from: BigInt('1'), to: 3 });
cidr.toArray({ from: '50.165.190.1', to: '50.165.190.3' });

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

Client side

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

API

.formatIP(address, [options])

to return an "ip-address" module object in the necessary format

.isValidAddress(address)

to check the address is valid or not (ip or cidr)

.isValidCIDR(address)

to check the address is valid (only cidr)

.createAddress(address)

to create an object address from the string

.prototype.contains(address)

to check the address belongs to the range

.prototype.start([options])

to get the start ip address

.prototype.end([options])

to get the end ip address

.prototype.toString()

to convert the cidr to a string like "50.165.190.0/23"

.prototype.toRange([options])

to convert the cidr to an array with start and end ip addresses [startIp, endIp]

.prototype.toObject([options])

to convert the cidr to an object with start and end ip addresses {start: startIp, end: endIp}

.prototype.toArray([options], [results])

to convert the cidr to an array with all ip addresses in the range
you can get information by chunks using options.from/options.limit or options.from/options.to
you can pass the second argument "results" (object) to get all chunk pagination information

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

to run fn for each element of the range
you can use the same chunk options as in .toArray()