Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ jobs:
- name: Check types
run: deno check src tests --sloppy-imports

- name: Check formatting
run: deno fmt --check

- name: Test
run: deno task test

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
analyze:
name: Analyse (${{ matrix.language }})
runs-on: 'ubuntu-latest'
runs-on: "ubuntu-latest"
timeout-minutes: 360
permissions:
security-events: write
Expand Down
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions .idea/copyright/Copyright_Cloudnode___LGPL_3_0.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/dictionaries/project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions .idea/runConfigurations/build.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions .idea/runConfigurations/test.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
[![CI](https://github.com/cloudnode-pro/ip/actions/workflows/ci.yml/badge.svg)](https://github.com/cloudnode-pro/ip/actions/workflows/ci.yml)
![Coverage: 100%](https://img.shields.io/badge/coverage-100%25-brightgreen)

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

[**Documentation — API Reference**](https://ip.cldn.pro)

Expand All @@ -25,47 +26,49 @@ npm install @cldn/ip
Import and use:

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

### Deno

Import the package from npm using the standard prefix:

```ts
import {IPv4, IPv6, Subnet} from "npm:@cldn/ip";
import { IPv4, IPv6, Subnet } from "npm:@cldn/ip";
```

### Browsers

For browser usage, it is recommended to use a bundler like [Vite](https://vitejs.dev/),
or [Webpack](https://webpack.js.org/). If you are using a bundler, follow the same usage as for Node.js.
For browser usage, it is recommended to use a bundler like
[Vite](https://vitejs.dev/), or [Webpack](https://webpack.js.org/). If you are
using a bundler, follow the same usage as for Node.js.

Alternatively, you can import the library as
a [JavaScript module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
Alternatively, you can import the library as a
[JavaScript module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
from [ESM>CDN](https://esm.sh/):

```html

<script type="module">
import {IPv4, IPv6, Subnet} from "https://esm.sh/@cldn/ip";
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).
- 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.
- Zero dependencies; compatible with frontend and backend environments without
requiring polyfills.

## Example

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

// Parse IPv4 address
const ip = IPv4.fromString("213.0.113.42");
Expand All @@ -80,13 +83,15 @@ console.log(subnet.contains(ip)); // true

## Contact

For bugs, or feature requests, please use [GitHub Issues](https://github.com/cloudnode-pro/ip/issues).
For bugs, or feature requests, please use
[GitHub Issues](https://github.com/cloudnode-pro/ip/issues).

For real-time chat or community discussions, join our Matrix
space: [#community\:cloudnode.pro](https://matrix.to/#/%23community:cloudnode.pro).
For real-time chat or community discussions, join our Matrix space:
[#community\:cloudnode.pro](https://matrix.to/#/%23community:cloudnode.pro).

## Licence

Copyright © 2024–2025 Cloudnode OÜ.

This project is licensed under the terms of the [LGPL-3.0](https://github.com/cloudnode-pro/ip/blob/master/COPYING) licence.
This project is licensed under the terms of the
[LGPL-3.0](https://github.com/cloudnode-pro/ip/blob/master/COPYING) licence.
53 changes: 27 additions & 26 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
import {defineConfig} from "vitepress";
import { defineConfig } from "vitepress";
import typedocSidebar from "../api/typedoc-sidebar.json";

// https://vitepress.dev/reference/site-config
export default defineConfig({
title: "@cldn/ip",
description: "Documentation",
cleanUrls: true,
themeConfig: {
nav: [
{text: "API Reference", link: "/api/"},
],
title: "@cldn/ip",
description: "Documentation",
cleanUrls: true,
themeConfig: {
nav: [
{ text: "API Reference", link: "/api/" },
],

sidebar: [
{
text: "API",
items: typedocSidebar,
},
],
sidebar: [
{
text: "API",
items: typedocSidebar,
},
],

outline: [2, 3],
outline: [2, 3],

socialLinks: [
{icon: "github", link: "https://github.com/cloudnode-pro/ip"},
{icon: "matrix", link: "https://matrix.to/#/@cloudnode:matrix.org"},
],
socialLinks: [
{ icon: "github", link: "https://github.com/cloudnode-pro/ip" },
{ icon: "matrix", link: "https://matrix.to/#/@cloudnode:matrix.org" },
],

search: {
provider: "local",
},
search: {
provider: "local",
},

footer: {
copyright: `Copyright © 2024–2025 Cloudnode OÜ.`,
message: `Released under the <a href="https://github.com/cloudnode-pro/ip/blob/master/COPYING" target="_blank">LGPL-3.0</a> licence.`
}
footer: {
copyright: `Copyright © 2024–2025 Cloudnode OÜ.`,
message:
`Released under the <a href="https://github.com/cloudnode-pro/ip/blob/master/COPYING" target="_blank">LGPL-3.0</a> licence.`,
},
},
});
12 changes: 6 additions & 6 deletions src/IP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
* You should have received a copy of the GNU Lesser General Public License along with @cldn/ip.
* If not, see <https://www.gnu.org/licenses/>
*/
import {IPv4} from "./IPv4.js";
import {IPv6} from "./IPv6.js";
import { IPv4 } from "./IPv4.js";
import { IPv6 } from "./IPv6.js";

/**
* An {@link IPv4} or {@link IPv6} address.
*/
export type IP = IPv4 | IPv6;

export namespace IP {
/**
* An {@link IPv4} or {@link IPv6} address class.
*/
export type Class = typeof IPv4 | typeof IPv6;
/**
* An {@link IPv4} or {@link IPv6} address class.
*/
export type Class = typeof IPv4 | typeof IPv6;
}
Loading
Loading