API reference › @evolu/common › Type › Ipv6Address
const Ipv6Address: brand(
"Ipv6Address",
String,
(value: string) =>
canonicalizeIpv6Address(value) === value
? ok()
: err<Ipv6AddressError>({ type: "Ipv6Address", value }),
formatIpv6AddressError,
);
Defined in: packages/common/src/Type.ts:9362
IPv6 address in its canonical text form, as defined by RFC 5952.
RFC 4291 allows many spellings of one address: 2001:DB8::1, 2001:0db8::1,
and 2001:db8:0:0:0:0:0:1 all name 2001:db8::1. Ipv6Address accepts only
the canonical spelling, so equal addresses are equal strings: lowercase
hexadecimal groups without leading zeros, with :: replacing the longest run
of two or more zero groups, the first one on a tie. IPv4-mapped addresses use
the mixed notation of RFC 5952 section 5, such as ::ffff:1.2.3.4, while
WHATWG URL hosts write them in hexadecimal, such as [::ffff:102:304].
Ipv6Address does not normalize; use Ipv6AddressFromString to convert
other spellings to the canonical one. Zone identifiers, such as %eth0, are
rejected, because they name a network interface of one device and mean
nothing on another. Brackets, prefix lengths, and whitespace are rejected
too; remove them before validating.
Example
import { assertEqual, assertErr, assertOk, Ipv6Address } from "@evolu/common";
assertOk(Ipv6Address.fromUnknown("2001:db8::1"), "2001:db8::1");
assertOk(Ipv6Address.fromUnknown("::ffff:1.2.3.4"), "::ffff:1.2.3.4");
const invalid = Ipv6Address.fromUnknown("2001:DB8::1");
assertErr(invalid);
assertEqual(invalid.error, {
type: "Ipv6Address",
value: "2001:DB8::1",
});