stringifyAddressv4(address: Addressv4 | ParsedAddressv4): string
Stringifies an IPv4 address to dotted decimal notation.
Takes either the bare 32-bit unsigned integer or a ParsedAddressv4;
given the latter, a truthy zoneId is appended after %, so
stringifyAddressv4(parseAddressv4(s)) gives back s for every accepted
s in canonical form. zoneId must not contain %, / or whitespace:
a zone containing any of them cannot be written in RFC 4007 textual form
at all, because % is the delimiter, and the result would not re-parse.
If you are producing a URI, percent-encode it there (RFC 9844,
[fe80::1%25eth0]); this package does not apply that transform, since
%25 is also a valid interface index 25.
Basic stringifying
Basic stringifying
import { assertEquals } from "@std/assert"; import { stringifyAddressv4 } from "@hertzg/ip/addressv4"; assertEquals(stringifyAddressv4(3232235777), "192.168.1.1"); assertEquals(stringifyAddressv4(167772161), "10.0.0.1"); assertEquals(stringifyAddressv4(0), "0.0.0.0"); assertEquals(stringifyAddressv4(4294967295), "255.255.255.255");
A parse result round-trips, zone included
A parse result round-trips, zone included
import { assertEquals } from "@std/assert"; import { parseAddressv4, stringifyAddressv4 } from "@hertzg/ip/addressv4"; assertEquals(stringifyAddressv4(parseAddressv4("192.168.1.1%ether1")), "192.168.1.1%ether1"); assertEquals(stringifyAddressv4({ address: 3232235777 }), "192.168.1.1"); assertEquals(stringifyAddressv4({ address: 3232235777, zoneId: "" }), "192.168.1.1");
address: Addressv4 | ParsedAddressv4
The address as a 32-bit unsigned integer, or a parse result