Skip to content

Commit 631567a

Browse files
authored
Breaking: redesigned several library APIs (#56)
2 parents 4ac9117 + 28ac2f4 commit 631567a

29 files changed

+5401
-1452
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ jobs:
136136

137137
- name: Generate docs
138138
if: "!github.event.release.prerelease"
139-
run: npm run docs
139+
run: npm run docs:build
140140

141141
- name: Set up GitHub pages
142142
if: "!github.event.release.prerelease"
@@ -146,7 +146,7 @@ jobs:
146146
if: "!github.event.release.prerelease"
147147
uses: actions/upload-pages-artifact@v3
148148
with:
149-
path: docs
149+
path: docs/.vitepress/dist
150150

151151
- name: Deploy to GitHub Pages
152152
if: "!github.event.release.prerelease"

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
node_modules/
22
dist/
3-
docs/
3+
docs/api/
4+
docs/.vitepress/dist/
5+
docs/.vitepress/cache/
6+
coverage/
7+
html/

.idea/compiler.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/dictionaries/project.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,92 @@
11
# @cldn/ip
22

3-
IP address utility.
3+
[![Documentation](https://img.shields.io/badge/Documentation-blue)](https://ip.cldn.pro)
4+
[![GitHub](https://img.shields.io/badge/GitHub-181717?logo=github)](https://github.com/cloudnode-pro/ip)
5+
[![NPM](https://img.shields.io/npm/v/@cldn/ip.svg)](https://www.npmjs.com/package/@cldn/ip)
6+
[![Downloads](https://img.shields.io/npm/d18m/@cldn/ip.svg)](https://www.npmjs.com/package/@cldn/ip)
7+
[![Licence](https://img.shields.io/github/license/cloudnode-pro/ip)](https://github.com/cloudnode-pro/ip/blob/master/COPYING)
8+
[![CI](https://github.com/cloudnode-pro/ip/actions/workflows/ci.yml/badge.svg)](https://github.com/cloudnode-pro/ip/actions/workflows/ci.yml)
9+
![Coverage: 100%](https://img.shields.io/badge/coverage-100%25-brightgreen)
410

5-
## Features
11+
A modern, object-oriented TypeScript library for representing and performing arithmetic on IP addresses and subnets.
12+
13+
[**Documentation — API Reference**](https://ip.cldn.pro)
614

7-
- Works in the browser and in Node.js without any polyfills. (A bundler like Webpack or Vite is recommended for the
8-
browser)
9-
- IPv4 and IPv6 classes.
10-
- Get IP address as BigInt, binary or string.
11-
- Extract IPv4-mapped IPv6 addresses.
12-
- Subnet class with methods to check IP membership, create netmask, list addresses, etc.
13-
- Network class for working with multiple subnets.
14-
- Written in TypeScript.
15+
## Usage
1516

16-
See the [**Documentation**](https://ip.cldn.pro)
17+
### Node.js
1718

18-
## Installation
19+
Install with `npm`:
1920

2021
```sh
2122
npm install @cldn/ip
2223
```
2324

24-
## Usage
25+
Import and use:
2526

2627
```ts
2728
import {IPv4, IPv6, Subnet} from "@cldn/ip";
29+
```
30+
31+
### Deno
2832

29-
const ipv6 = IPv4.fromString("::ffff:192.168.1.42");
30-
const ipv4 = ipv6.getMappedIPv4();
33+
Import the package from npm using the standard prefix:
3134

32-
const subnet = Subnet.fromString("192.168.0.0/16");
33-
subnet.has(ipv4); // true
35+
```ts
36+
import {IPv4, IPv6, Subnet} from "npm:@cldn/ip";
3437
```
3538

36-
## Licence
39+
### Browsers
40+
41+
For browser usage, it is recommended to use a bundler like [Vite](https://vitejs.dev/),
42+
or [Webpack](https://webpack.js.org/). If you are using a bundler, follow the same usage as for Node.js.
43+
44+
Alternatively, you can import the library as
45+
a [JavaScript module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
46+
from [ESM>CDN](https://esm.sh/):
47+
48+
```html
49+
50+
<script type="module">
51+
import {IPv4, IPv6, Subnet} from "https://esm.sh/@cldn/ip";
52+
</script>
53+
```
3754

38-
Copyright © 2024–2025 Cloudnode OÜ
55+
## Features
56+
57+
- Object-oriented representation of IPv4 and IPv6 addresses, and subnets.
58+
- Comprehensive subnet arithmetic operations (e.g., containment, splitting, merging).
59+
- Support for CIDR notation for defining and parsing subnets.
60+
- Easy definition and manipulation of networks and collections of subnets.
61+
- Support for IPv4-mapped IPv6 addresses.
62+
- Fully documented, fully typed, and thoroughly tested with 100% coverage.
63+
- Zero dependencies; compatible with frontend and backend environments without requiring polyfills.
64+
65+
## Example
66+
67+
```ts
68+
import {IPv4, Subnet} from "@cldn/ip";
69+
70+
// Parse IPv4 address
71+
const ip = IPv4.fromString("213.0.113.42");
72+
// Or use IPAddress.fromString("213.0.113.42") to parse either IPv4 or IPv6
73+
74+
// Create subnet from CIDR notation
75+
const subnet = Subnet.fromCIDR("213.0.113.0/24");
3976

40-
This file is part of @cldn/ip.
77+
// Check if IP is within subnet
78+
console.log(subnet.contains(ip)); // true
79+
```
80+
81+
## Contact
82+
83+
For bugs, or feature requests, please use [GitHub Issues](https://github.com/cloudnode-pro/ip/issues).
84+
85+
For real-time chat or community discussions, join our Matrix
86+
space: [#community\:cloudnode.pro](https://matrix.to/#/%23community:cloudnode.pro).
87+
88+
## Licence
4189

42-
@cldn/ip is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
43-
Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
44-
later version.
90+
Copyright © 2024–2025 Cloudnode OÜ.
4591

46-
@cldn/ip is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
47-
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
48-
details.
92+
This project is licensed under the terms of the [LGPL-3.0](https://github.com/cloudnode-pro/ip/blob/master/COPYING) licence.

docs/.vitepress/config.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import {defineConfig} from "vitepress";
2+
import typedocSidebar from "../api/typedoc-sidebar.json";
3+
4+
// https://vitepress.dev/reference/site-config
5+
export default defineConfig({
6+
title: "@cldn/ip",
7+
description: "Documentation",
8+
cleanUrls: true,
9+
themeConfig: {
10+
nav: [
11+
{text: "API Reference", link: "/api/"},
12+
],
13+
14+
sidebar: [
15+
{
16+
text: "API",
17+
items: typedocSidebar,
18+
},
19+
],
20+
21+
outline: [2, 3],
22+
23+
socialLinks: [
24+
{icon: "github", link: "https://github.com/cloudnode-pro/ip"},
25+
{icon: "matrix", link: "https://matrix.to/#/@cloudnode:matrix.org"},
26+
],
27+
28+
search: {
29+
provider: "local",
30+
},
31+
32+
footer: {
33+
copyright: `Copyright © 2024–2025 Cloudnode OÜ.`,
34+
message: `Released under the <a href="https://github.com/cloudnode-pro/ip/blob/master/COPYING" target="_blank">LGPL-3.0</a> licence.`
35+
}
36+
},
37+
});

docs/index.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
# https://vitepress.dev/reference/default-theme-home-page
3+
layout: home
4+
5+
hero:
6+
name: "@cldn/ip"
7+
text: "Documentation"
8+
tagline: A modern, object-oriented TypeScript library for representing and performing arithmetic on IP addresses and subnets.
9+
actions:
10+
- theme: brand
11+
text: API Reference
12+
link: /api/
13+
14+
features:
15+
- title: Unified IP Types
16+
details: Object-oriented classes for IPv4 and IPv6, with full support for IPv4-mapped IPv6 addresses.
17+
18+
- title: Subnet Logic
19+
details: Perform checks, splits, merges, and other operations on CIDR-based subnets.
20+
21+
- title: Network Modelling
22+
details: Build and work with networks and subnet sets using simple, composable tools.
23+
24+
- title: Typed and Minimal
25+
details: Fully typed, thoroughly tested, and dependency-free. Works in any JS or TS environment.
26+
---

0 commit comments

Comments
 (0)