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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ipdo

v0.0.4

Published

High-performance IP address manipulation library with CIDR, IPv4/IPv6, and network operations

Downloads

541

Readme

ipdo 🔍

npm version npm downloads npm license Contributor Covenant

A powerful and efficient IP address manipulation library.

✨ Features

  • 🌐 Complete IP address manipulation
    • 📍 IPv4 and IPv6 support
    • 🔢 CIDR range operations
    • ✅ IP address validation
    • 🎯 Network mask calculations
    • 🔄 Binary and numeric conversions
    • 🏷️ IP address type detection (private, loopback, multicast)
    • ➕ IP address arithmetic
    • 📦 ArrayBuffer conversions for network protocols
  • 🚀 Zero dependencies
  • 📝 TypeScript support
  • 🛡️ Comprehensive error handling
  • ⚡️ High performance bitwise operations
  • 📦 Modern ESM and CJS support

📥 Installation

# Using npm
npm install ipdo

# Using yarn
yarn add ipdo

# Using pnpm
pnpm add ipdo

🚀 Basic Usage

import {
  isIPv4,
  isIPv6,
  isValidIP,
  isPrivateIPv4,
  nextIPv4,
  parseCIDR,
  ipInRange,
  firstIPInRange,
  lastIPInRange,
  maskForCIDR,
  rangeSize,
  ipv4ToBuffer,
  ipv6ToBuffer,
  bufferToIPv4,
  bufferToIPv6,
} from "ipdo";

// IP address validation
console.log(isValidIP("192.168.0.1")); // true
console.log(isValidIP("not an ip")); // false
console.log(isIPv4("192.168.0.1")); // true
console.log(isIPv6("2001:db8::")); // true

// IP address type checks
console.log(isPrivateIPv4("192.168.0.1")); // true
console.log(isPrivateIPv4("8.8.8.8")); // false

// IP address arithmetic
console.log(nextIPv4("192.168.0.1")); // '192.168.0.2'
console.log(prevIPv4("192.168.0.1")); // '192.168.0.0'

// CIDR range operations
const range = parseCIDR("192.168.0.0/24");
console.log(ipInRange("192.168.0.0/24", "192.168.0.1")); // true
console.log(ipInRange("192.168.0.0/24", "192.168.1.1")); // false
console.log(firstIPInRange("192.168.0.0/24")); // '192.168.0.0'
console.log(lastIPInRange("192.168.0.0/24")); // '192.168.0.255'
console.log(maskForCIDR("192.168.0.0/24")); // '255.255.255.0'
console.log(rangeSize("192.168.0.0/24")); // 256

🔧 Advanced Usage

🌐 IPv6 Operations

import {
  isIPv6,
  isPrivateIPv6,
  nextIPv6,
  parseCIDR,
  ipInRange,
  firstIPInRange,
  lastIPInRange,
  rangesOverlap,
} from "ipdo";

console.log(ipInRange("2001:db8::/32", "2001:db8::1")); // true
console.log(ipInRange("2001:db8::/32", "2001:db9::1")); // false
console.log(firstIPInRange("2001:db8::/32")); // '2001:db8:0000:0000:0000:0000:0000:0000'
console.log(lastIPInRange("2001:db8::/32")); // '2001:db8:ffff:ffff:ffff:ffff:ffff:ffff'
console.log(isPrivateIPv6("fc00::1")); // true
console.log(nextIPv6("2001:db8::")); // '2001:db8::1'

🔄 Range Overlap Checking

import { rangesOverlap } from "ipdo";

console.log(rangesOverlap("192.168.0.0/24", "192.168.0.128/25")); // true
console.log(rangesOverlap("192.168.0.0/24", "10.0.0.0/24")); // false

🔄 Binary and Numeric Conversions

import {
  ipv4ToInt,
  intToIPv4,
  ipv6ToBigInt,
  bigIntToIPv6,
  toBinary,
  toNumber,
} from "ipdo";

// IPv4 conversions
console.log(ipv4ToInt("192.168.0.1")); // 3232235521
console.log(intToIPv4(3232235521)); // '192.168.0.1'

// IPv6 conversions
console.log(ipv6ToBigInt("2001:db8::")); // 42540766452641154071740215577757643584n
console.log(bigIntToIPv6(42540766452641154071740215577757643584n)); // '2001:db8::'

// Generic conversions
console.log(toBinary("192.168.0.1")); // '11000000101010000000000000000001'
console.log(toNumber("192.168.0.1")); // 3232235521

🔄 Buffer Conversions

import { ipv4ToBuffer, ipv6ToBuffer, bufferToIPv4, bufferToIPv6 } from "ipdo";

// IPv4 buffer conversions
const ipv4Buffer = ipv4ToBuffer("192.168.0.1"); // ArrayBuffer (4 bytes)
console.log(ipv4Buffer.byteLength); // 4
const ipv4String = bufferToIPv4(ipv4Buffer); // '192.168.0.1'

// IPv6 buffer conversions (supports compressed notation)
const ipv6Buffer = ipv6ToBuffer("2001:db8::"); // ArrayBuffer (16 bytes)
console.log(ipv6Buffer.byteLength); // 16
const ipv6String = bufferToIPv6(ipv6Buffer); // '2001:0db8:0000:0000:0000:0000:0000:0000'

// Round-trip conversion
const compressedIPv6 = "2001:db8::1";
const buffer = ipv6ToBuffer(compressedIPv6);
const expandedIPv6 = bufferToIPv6(buffer); // Fully expanded format

📚 API Reference

🔍 IP Address Validation

isIPv4(ip: string): boolean

Check if a string is a valid IPv4 address.

isIPv6(ip: string): boolean

Check if a string is a valid IPv6 address.

isValidIP(ip: string): boolean

Check if a string is a valid IP address (IPv4 or IPv6).

🔄 IP Address Conversions

ipv4ToInt(ip: string): number

Convert IPv4 address to 32-bit number.

intToIPv4(int: number): string

Convert number to IPv4 address.

ipv6ToBigInt(ip: string): bigint

Convert IPv6 address to BigInt.

bigIntToIPv6(int: bigint): string

Convert BigInt to IPv6 address.

toBinary(ip: string): string

Convert IP address to binary string.

toNumber(ip: string): number | bigint

Convert IP address to numeric value.

🔄 Buffer Conversions

ipv4ToBuffer(ip: string): ArrayBuffer

Convert IPv4 address to ArrayBuffer (4 bytes).

ipv6ToBuffer(ip: string): ArrayBuffer

Convert IPv6 address to ArrayBuffer (16 bytes). Supports compressed notation.

bufferToIPv4(buffer: ArrayBuffer): string

Convert ArrayBuffer (4 bytes) to IPv4 address.

bufferToIPv6(buffer: ArrayBuffer): string

Convert ArrayBuffer (16 bytes) to IPv6 address.

🏷️ IP Address Type Detection

isPrivateIPv4(ip: string | number): boolean

Check if IPv4 address is private.

isLoopbackIPv4(ip: string | number): boolean

Check if IPv4 address is loopback.

isMulticastIPv4(ip: string | number): boolean

Check if IPv4 address is multicast.

isPrivateIPv6(ip: string | bigint): boolean

Check if IPv6 address is private.

isLoopbackIPv6(ip: string | bigint): boolean

Check if IPv6 address is loopback.

isMulticastIPv6(ip: string | bigint): boolean

Check if IPv6 address is multicast.

➕ IP Address Arithmetic

nextIPv4(ip: string | number): string

Get next IPv4 address.

prevIPv4(ip: string | number): string

Get previous IPv4 address.

nextIPv6(ip: string | bigint): string

Get next IPv6 address.

prevIPv6(ip: string | bigint): string

Get previous IPv6 address.

🌐 CIDR Range Operations

parseCIDR(cidr: string): object

Parse CIDR notation to range information.

ipInRange(cidr: string, ip: string): boolean

Check if IP address is in CIDR range.

firstIPInRange(cidr: string): string

Get first IP address in CIDR range.

lastIPInRange(cidr: string): string

Get last IP address in CIDR range.

maskForCIDR(cidr: string): string

Get network mask for CIDR.

rangeSize(cidr: string): number | bigint

Get total number of addresses in CIDR range.

rangesOverlap(cidr1: string, cidr2: string): boolean

Check if two CIDR ranges overlap.

⚠️ Error Handling

The library throws descriptive errors for:

  • 🚫 Invalid IP address format
  • 📏 Invalid prefix length (must be 0-32 for IPv4, 0-128 for IPv6)
  • ❌ Mismatched IP version
  • 🚫 Invalid CIDR notation

📄 License

MIT © Funish