zena:url

zena
import {…} from 'zena:url';

Classes

URL

zena
final class URL
Re-exported from zena:url/url.zena

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).

Constructors
zena
new(rec: UrlRecord)
#
Properties
zena
protocol: String { get; }
#
zena
username: String { get; }
#
zena
password: String { get; }
#
zena
hostname: String { get; }
#
zena
port: String { get; }
#
zena
pathname: String { get; }
#
zena
hash: String { get; }
#
zena
href: String { get; }
#
Methods
zena
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.

zena
static canParse(input: String, base: String | null = null): boolean
#
zena
host(): String
#

"hostname:port", with the port omitted when it is null.

zena
origin(): String
#
zena
toString(): String
#

Enums

EncodeSet

zena
enum EncodeSet
Re-exported from zena:url/encoding.zena

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).

Members
zena
C0Control
#
zena
Fragment
#
zena
Query
#
zena
SpecialQuery
#
zena
Path
#
zena
Userinfo
#
zena
Component
#
zena
FormUrlencoded
#

Functions

byteNeedsPercentEncoding

zena
function byteNeedsPercentEncoding(b: i32, set: EncodeSet): boolean
Re-exported from zena:url/encoding.zena

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

zena
function percentEncode(input: String, set: EncodeSet, spaceAsPlus: boolean = false): String
Re-exported from zena:url/encoding.zena

Percent-encodes input for the given encode set. spaceAsPlus implements the form-urlencoded serializer's special case (0x20 → '+').

percentDecode

zena
function percentDecode(input: String, plusAsSpace: boolean = false): String
Re-exported from zena:url/encoding.zena

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

zena
function encodeByteInto(sb: StringBuilder, b: i32, set: EncodeSet): void
Re-exported from zena:url/encoding.zena

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

zena
function parseFormUrlencoded(input: String): Array<(String, String)>
Re-exported from zena:url/encoding.zena

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

zena
function serializeFormUrlencoded(pairs: Array<(String, String)>): String
Re-exported from zena:url/encoding.zena

Serializes ordered (name, value) pairs to application/x-www-form-urlencoded (https://url.spec.whatwg.org/#concept-urlencoded-serializer).