function stringifyAddressv6Expanded
stringifyAddressv6Expanded(address: Addressv6 | ParsedAddressv6): string

Stringifies an IPv6 address to full uncompressed colon-hexadecimal notation.

Every one of the 8 groups is written with all 4 hex digits, and no run of zero groups is replaced with ::. This is the counterpart of stringifyAddressv6, which produces the canonical compressed form. To expand a string, parse it first: stringifyAddressv6Expanded(parseAddressv6(s)).

Takes either the bare 128-bit bigint or a ParsedAddressv6; given the latter, a truthy zoneId is appended after %. The zone constraint of stringifyAddressv6 applies: no %, / or whitespace.

Examples

Basic stringifying

import { assertEquals } from "@std/assert";
import { stringifyAddressv6Expanded } from "@hertzg/ip/addressv6";

assertEquals(stringifyAddressv6Expanded(0n), "0000:0000:0000:0000:0000:0000:0000:0000");
assertEquals(stringifyAddressv6Expanded(1n), "0000:0000:0000:0000:0000:0000:0000:0001");
assertEquals(stringifyAddressv6Expanded(42540766411282592856903984951653826561n), "2001:0db8:0000:0000:0000:0000:0000:0001");

Expanding a string, zone included

import { assertEquals } from "@std/assert";
import { parseAddressv6, stringifyAddressv6, stringifyAddressv6Expanded } from "@hertzg/ip/addressv6";

const address = parseAddressv6("2001:db8::1");
assertEquals(stringifyAddressv6(address), "2001:db8::1");
assertEquals(stringifyAddressv6Expanded(address), "2001:0db8:0000:0000:0000:0000:0000:0001");
assertEquals(
  stringifyAddressv6Expanded(parseAddressv6("fe80::1%eth0")),
  "fe80:0000:0000:0000:0000:0000:0000:0001%eth0",
);

Error handling

import { assertThrows } from "@std/assert";
import { stringifyAddressv6Expanded } from "@hertzg/ip/addressv6";

assertThrows(() => stringifyAddressv6Expanded(-1n), RangeError);
assertThrows(() => stringifyAddressv6Expanded(340282366920938463463374607431768211456n), RangeError);

Parameters

The address as a 128-bit bigint, or a parse result

Return Type

string

The IPv6 address string with all 8 groups written in full, %zoneId appended when there is one

Throws

RangeError

If the address is negative or greater than 2^128-1

Usage

import { stringifyAddressv6Expanded } from "addressv6.ts";