|
1 | 1 | # @cldn/ip
|
2 | 2 |
|
3 |
| -IP address utility. |
| 3 | +[](https://ip.cldn.pro) |
| 4 | +[](https://github.com/cloudnode-pro/ip) |
| 5 | +[](https://www.npmjs.com/package/@cldn/ip) |
| 6 | +[](https://www.npmjs.com/package/@cldn/ip) |
| 7 | +[](https://github.com/cloudnode-pro/ip/blob/master/COPYING) |
| 8 | +[](https://github.com/cloudnode-pro/ip/actions/workflows/ci.yml) |
| 9 | + |
4 | 10 |
|
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) |
6 | 14 |
|
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 |
15 | 16 |
|
16 |
| -See the [**Documentation**](https://ip.cldn.pro) |
| 17 | +### Node.js |
17 | 18 |
|
18 |
| -## Installation |
| 19 | +Install with `npm`: |
19 | 20 |
|
20 | 21 | ```sh
|
21 | 22 | npm install @cldn/ip
|
22 | 23 | ```
|
23 | 24 |
|
24 |
| -## Usage |
| 25 | +Import and use: |
25 | 26 |
|
26 | 27 | ```ts
|
27 | 28 | import {IPv4, IPv6, Subnet} from "@cldn/ip";
|
| 29 | +``` |
| 30 | + |
| 31 | +### Deno |
28 | 32 |
|
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: |
31 | 34 |
|
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"; |
34 | 37 | ```
|
35 | 38 |
|
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 | +``` |
37 | 54 |
|
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"); |
39 | 76 |
|
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 |
41 | 89 |
|
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Ü. |
45 | 91 |
|
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. |
0 commit comments