zena:url
import {…} from 'zena:url';
Classes
URL
final class URL
An immutable, parsed URL. Components are exposed with the same names and
string shapes as the web API (protocol includes ':', search includes
'?', hash includes '#', all empty when absent).
new(rec: UrlRecord)
static parse(input: String, base: String | null = null): URL | null
Parses input, optionally resolving it against base, and returns null
if either fails to parse.
A URL that does not parse is an ordinary, recoverable outcome rather than an exceptional one, so there is no throwing constructor. Nothing is lost by returning null: the spec's own failure mode is the bare word "failure" — there is no error code, position, or reason to hand back.
static canParse(input: String, base: String | null = null): boolean
host(): String
"hostname:port", with the port omitted when it is null.
origin(): String
https://url.spec.whatwg.org/#concept-url-origin ("null" when opaque).
toString(): String
Enums
EncodeSet
enum EncodeSet
The percent-encode sets defined by the URL Standard. Each set includes all of the sets above it (C0 control ⊂ fragment ⊂ ... is not a strict chain — fragment and query diverge — but every set includes the C0 control set).
Functions
byteNeedsPercentEncoding
function byteNeedsPercentEncoding(b: i32, set: EncodeSet): boolean
True when byte b must be percent-encoded for set. Bytes outside
0x20..0x7E (C0 controls, DEL, and all non-ASCII bytes) are encoded in every
set.
percentEncode
function percentEncode(input: String, set: EncodeSet, spaceAsPlus: boolean = false): String
Percent-encodes input for the given encode set. spaceAsPlus implements
the form-urlencoded serializer's special case (0x20 → '+').
percentDecode
function percentDecode(input: String, plusAsSpace: boolean = false): String
Percent-decodes input (https://url.spec.whatwg.org/#percent-decode).
A '%' not followed by two hex digits is passed through unchanged, per spec.
plusAsSpace implements the form-urlencoded parser's '+' → 0x20 rule.
encodeByteInto
function encodeByteInto(sb: StringBuilder, b: i32, set: EncodeSet): void
Appends b to sb, percent-encoded if set requires it. This is the
byte-at-a-time form the URL parser builds components with.
parseFormUrlencoded
function parseFormUrlencoded(input: String): Array<(String, String)>
Parses an application/x-www-form-urlencoded string into ordered (name, value) pairs (https://url.spec.whatwg.org/#urlencoded-parsing). A leading '?' is NOT stripped here — callers strip it (the URL API layer does, matching URLSearchParams).
serializeFormUrlencoded
function serializeFormUrlencoded(pairs: Array<(String, String)>): String
Serializes ordered (name, value) pairs to application/x-www-form-urlencoded (https://url.spec.whatwg.org/#concept-urlencoded-serializer).