Skip to content

Repository files navigation

@cldn/ip

DocumentationGitHubNPMDownloadsLicenceJSR ScoreCICoverage: 100%

A modern, object-oriented TypeScript library for representing and performing arithmetic on IP addresses and subnets.

Documentation — API Reference

Usage

Installation

Install the package using your preferred environment:

# Node.js
npm install @cldn/ip
# Deno
deno add jsr:@cldn/ip
# Bun
bun install @cldn/ip

Import

import{IPv4,IPv6,Subnet}from"@cldn/ip";

Browsers

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>

Features

  • 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.

Example

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));// true

Contact

For bugs, or feature requests, please use GitHub Issues.

For real-time chat or community discussions, join our Matrix space: #community:cloudnode.pro.

Licence

Copyright © 2024–2026 Cloudnode OÜ.

This project is licensed under the terms of the LGPL-3.0 licence.

About

A modern, object-oriented TypeScript library for representing and performing arithmetic on IP addresses and subnets.

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages