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

node-iputils

v0.1.0

Published

A very small and simple library to handle IPv4- & IPv6-addresses.

Downloads

5

Readme

node-iputils

A quite small and simple IP-library with only a few classes. Tested & linted.

Features:

  • Handle IPv4 & IPv6 addresses and subnets with the same class.
  • Simply pass addresses into constructors, the library will decide what it is and how to handle it.
  • Calculate the first and last IP of a subnet.
  • Apply a mask to an IP address.
  • Find out if an IP is inside a subnet.
  • Increment or decrement IPs to get e.g. the next one.
  • Convert addresses to numbers and back.

Usage

Install using npm:

npm install node-iputils

Now use it in your code:

const { IPAddress } = require("node-iputils");

const ipSubnet = new IPAddress("192.168.0.0", 24);
const ipv4 = new IPAddress("192.168.0.5", 32);
ipSubnet.getSubnet().isInSubnet(ipv4) // => true

const ipv6Subnet = new IPAddress("fde8:894a:40c:ee20::", 64);
const ipv6 = new IPAddress("fde8:894a:40c:ee20:0::05:5", 128);
ipv6Subnet.getSubnet().isInSubnet(ipv6) // => true

/* The following functions also work for IPv4-addresses */
ipv6.maximize() // => fde8:894a:040c:ee20:0000:0000:0005:0005
ipv6.minimize() // => fde8:894a:040c:ee20::5:5
ipv6.asNumber() // => 337502080359017093851530813254247186437n

const ipv6FromNumber = IPAddress.fromNumber(337502080359017093851530813254247186437n, 6); // => new IPAddress instance.

ipv4.maskAsNumber() // => 4294967295n

API documentation

Classes

InvalidIPError

Kind: global class

new InvalidIPError(ip, net)

| Param | Type | Description | | --- | --- | --- | | ip | string | The IP address which is invalid. | | net | string | The network mask which is invalid. |

InvalidConversionError

Kind: global class

IPAddress

Kind: global class

new IPAddress(ip, net)

| Param | Type | Description | | --- | --- | --- | | ip | string | The IP-address to store. | | net | string | The network mask to store. |

ipAddress.minimize() ⇒ string

Kind: instance method of IPAddress
Returns: string - The minimized IP-address.

ipAddress.maximize() ⇒ string

Kind: instance method of IPAddress
Returns: string - The maximized IP-address.

ipAddress.asNumber() ⇒ bigint

Kind: instance method of IPAddress
Returns: bigint - The IP-address as a number.

ipAddress.maskAsNumber() ⇒ bigint

Kind: instance method of IPAddress
Returns: bigint - The network mask as a number.

ipAddress.applyMask() ⇒ IPAddress

Kind: instance method of IPAddress
Returns: IPAddress - The masked IP-address.

ipAddress.increment(by) ⇒ IPAddress

Kind: instance method of IPAddress
Returns: IPAddress - The incremented IP address.

| Param | Type | Description | | --- | --- | --- | | by | number | The number to increment the IP address by. |

ipAddress.decrement(by) ⇒ IPAddress

Kind: instance method of IPAddress
Returns: IPAddress - The decremented IP address.

| Param | Type | Description | | --- | --- | --- | | by | number | The number to decrement the IP address by. |

ipAddress.getSubnet() ⇒ IPSubnet

Kind: instance method of IPAddress
Returns: IPSubnet - The subnet of the IP-address.

IPAddress.fromNumber(number, type) ⇒ IPAddress

Kind: static method of IPAddress
Returns: IPAddress - The IP address.

| Param | Type | Description | | --- | --- | --- | | number | bigint | The number to convert. | | type | number | The type of the IP address. 4 for IPv4 and 6 for IPv6. |

IPSubnet

Kind: global class

new IPSubnet(parent)

| Param | Type | Description | | --- | --- | --- | | parent | IPAddress | The parent IP address from which this subnet is generated. |

ipSubnet.isMatchingType(address)

Kind: instance method of IPSubnet
Throws:

| Param | Type | Description | | --- | --- | --- | | address | IPAddress | The address to check. |

ipSubnet.isInSubnet(address) ⇒ boolean

Kind: instance method of IPSubnet
Returns: boolean - True if the address is in the subnet, false otherwise.

| Param | Type | Description | | --- | --- | --- | | address | IPAddress | The address to check. |

ipSubnet.getBiggestIPAsNumber() ⇒ bigint

Kind: instance method of IPSubnet
Returns: bigint - The biggest IP address in the subnet as a number.

ipSubnet.getSmallestIPAsNumber() ⇒ bigint

Kind: instance method of IPSubnet
Returns: bigint - The smallest IP address in the subnet as a number.


© /dev/paul