A modern, object-oriented TypeScript library for representing and performing arithmetic on IP addresses and subnets.
Install the package using your preferred environment:
# Node.js
npm install @cldn/ip
# Deno
deno add jsr:@cldn/ip
# Bun
bun install @cldn/ipimport{IPv4,IPv6,Subnet}from"@cldn/ip";For browser usage, it is recommended to use a bundler like Vite or Webpack. If using a bundler, import as above.
Alternatively, load as a JavaScript module from ESM>CDN:
<scripttype="module">import{IPv4,IPv6,Subnet}from"https://esm.sh/@cldn/ip";</script>- Object-oriented representation of IPv4 and IPv6 addresses, and subnets.
- Comprehensive subnet arithmetic operations (e.g., containment, splitting, merging).
- Support for CIDR notation for defining and parsing subnets.
- Easy definition and manipulation of networks and collections of subnets.
- Support for IPv4-mapped IPv6 addresses.
- Fully documented, fully typed, and thoroughly tested with 100% coverage.
- Zero dependencies; compatible with frontend and backend environments without requiring polyfills.
import{IPv4,Subnet}from"@cldn/ip";// Parse IPv4 addressconstip=IPv4.fromString("213.0.113.42");// Or use IPAddress.fromString("213.0.113.42") to parse either IPv4 or IPv6// Create subnet from CIDR notationconstsubnet=Subnet.fromCIDR("213.0.113.0/24");// Check if IP is within subnetconsole.log(subnet.contains(ip));// trueFor bugs, or feature requests, please use GitHub Issues.
For real-time chat or community discussions, join our Matrix space: #community:cloudnode.pro.
Copyright © 2024–2026 Cloudnode OÜ.
This project is licensed under the terms of the LGPL-3.0 licence.