A modern, object-oriented TypeScript library for representing and performing arithmetic on IP addresses and subnets.
Install with npm
:
npm install @cldn/ip
Import and use:
import {IPv4, IPv6, Subnet} from "@cldn/ip";
Import the package from npm using the standard prefix:
import {IPv4, IPv6, Subnet} from "npm:@cldn/ip";
For browser usage, it is recommended to use a bundler like Vite, or Webpack. If you are using a bundler, follow the same usage as for Node.js.
Alternatively, you can import the library as a JavaScript module from ESM>CDN:
<script type="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 address
const ip = IPv4.fromString("213.0.113.42");
// Or use IPAddress.fromString("213.0.113.42") to parse either IPv4 or IPv6
// Create subnet from CIDR notation
const subnet = Subnet.fromCIDR("213.0.113.0/24");
// Check if IP is within subnet
console.log(subnet.contains(ip)); // true
For bugs, or feature requests, please use GitHub Issues.
For real-time chat or community discussions, join our Matrix space: #community:cloudnode.pro.
Copyright © 2024–2025 Cloudnode OÜ.
This project is licensed under the terms of the LGPL-3.0 licence.