ipv6Pack() function

Compresses an IPv6 address: drops leading zeros from each group and collapses the longest run of zero groups to ::.

Signature:

export declare function ipv6Pack(ip: string): string;

Parameters

Parameter

Type

Description

ip

string

a full or partly compressed IPv6 address

Returns:

string

The compressed form, e.g. 2001:0db8:0000:0000:0000:0000:0000:0001 becomes 2001:db8::1.

Remarks

The inverse of ipv6Unpack(), and what this package emits when producing IPv6 text. It is a string transformation with no validation, so a malformed input produces malformed output rather than an error.

Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.