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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ip-calc-regex

v1.1.1

Published

IP Calculator based on Netmask/CIDR/Host with regex validation

Downloads

6

Readme

ip-calc-regex

IP Calculator based on Netmask/CIDR/Host with regex validation.

Installation

npm install ip-calc-regex --save

Usage

// ES6 import
import { ipCalc } from 'ip-calc-regex';

// CommonJS require
const { ipCalc } = require('ip-calc-regex');

// Example: Calculate using CIDR notation
const result = ipCalc('192.168.1.1', 1, '24');
console.log(result);

Output

{
  'IP Address': '192.168.1.1',
  'Netmask': '255.255.255.0',
  'CIDR': '/24',
  'Wildcard': '0.0.0.255',
  'Class': 'Class C',
  'Network Address': '192.168.1.0',
  'Host min': '192.168.1.1',
  'Host max': '192.168.1.254',
  'Broadcast': '192.168.1.255',
  'Total Subnets': 256,
  'Total Hosts': '254'
}

Error Handling

If invalid input is provided, the function returns an error object:

{
  errorMsg: 'Invalid IP Address!' // or other error message
}

API

ipCalc(ipAddress, type, typeValue)

Parameters

| Parameter | Type | Description | Values | |-----------|------|-------------|--------| | ipAddress | string | IPv4 address | e.g., '192.168.100.1' | | type | number | Input type | 0 = Netmask1 = CIDR2 = Total Hosts | | typeValue | string | Value corresponding to the type | Depends on type parameter |

Return Value

Returns an object containing:

  • IP Address: Original IP address
  • Netmask: Subnet mask in dotted decimal notation
  • CIDR: CIDR notation (e.g., /24)
  • Wildcard: Wildcard mask
  • Class: IP address class (A, B, C, D, or E)
  • Network Address: Network address
  • Host min: First usable host address
  • Host max: Last usable host address
  • Broadcast: Broadcast address
  • Total Subnets: Total number of subnets
  • Total Hosts: Total usable hosts (formatted with dot separators)

Or an error object with errorMsg property if validation fails.

Examples

Using Netmask (type = 0)

ipCalc('192.168.1.1', 0, '255.255.255.0')

// Output:
// {
//   'IP Address': '192.168.1.1',
//   'Netmask': '255.255.255.0',
//   'CIDR': '/24',
//   'Wildcard': '0.0.0.255',
//   'Class': 'Class C',
//   'Network Address': '192.168.1.0',
//   'Host min': '192.168.1.1',
//   'Host max': '192.168.1.254',
//   'Broadcast': '192.168.1.255',
//   'Total Subnets': 256,
//   'Total Hosts': '254'
// }

Using CIDR Notation (type = 1)

ipCalc('172.20.78.0', 1, '24')

// Output:
// {
//   'IP Address': '172.20.78.0',
//   'Netmask': '255.255.255.0',
//   'CIDR': '/24',
//   'Wildcard': '0.0.0.255',
//   'Class': 'Class B',
//   'Network Address': '172.20.78.0',
//   'Host min': '172.20.78.1',
//   'Host max': '172.20.78.254',
//   'Broadcast': '172.20.78.255',
//   'Total Subnets': 65536,
//   'Total Hosts': '254'
// }

Using Host Count (type = 2)

ipCalc('192.168.1.1', 2, '12')

// Output:
// {
//   'IP Address': '192.168.1.1',
//   'Netmask': '255.240.0.0',
//   'CIDR': '/28',
//   'Wildcard': '0.15.255.255',
//   'Class': 'Class C',
//   'Network Address': '192.160.0.0',
//   'Host min': '192.160.0.1',
//   'Host max': '192.175.255.254',
//   'Broadcast': '192.175.255.255',
//   'Total Subnets': 16,
//   'Total Hosts': '14'
// }

Validation

The calculator validates:

  • IP Address: Must be a valid IPv4 address (0-255 for each octet)
  • Netmask: Must be a valid subnet mask
  • CIDR: Must be between 1 and 32
  • Host Count: Must be a positive integer

Features

  • ✅ Supports all IP classes (A, B, C, D, E)
  • ✅ Works with any valid CIDR notation (1-32)
  • ✅ Regex-based input validation
  • ✅ Calculates network address, broadcast, and host range
  • ✅ Computes total subnets and usable hosts
  • ✅ Well-documented code with JSDoc comments
  • ✅ No external dependencies

License

ISC

Author

Awal Ariansyah

Repository

https://github.com/snowfluke/ip-calc-regex