This is a tiny IPv4 and IPv6 utility library forked from ipaddr.js
.
Requires Node.js 18, 20 or above.
internet-address
supports tree shaking meaning you can pull in only the functionality you need versus ipaddr.js
's
all or nothing approach.
Pulling in every module costs under 3KiB minified and gzipped. This package supports tree shaking however meaning if you only need IPv4 parsing for example, it'll only cost you 1.1KiB instead of the full 3KiB.
This package is written in standard ESM using only JavaScript builtins meaning it can be imported into browsers via a CDN without Node.js polyfills:
import { IPv4, IPv6, CIDR, process, subnetMatch } from "https://esm.sh/internet-address"
An IPv4 address is an array of 4 bytes so IPv4.parse()
returns you a Uint8Array
of 4 bytes. No need for
serialization, the data type is already in its basic form.
Install with npm install internet-address
. Make sure you have "type": "module"
in your package.json
.
Import the utilities with:
import { IPv4, IPv6, CIDR, process, subnetMatch } from "internet-address"
Documentation can be found on TS Docs.