velt/net/url
API referenceA WHATWG-style URL and URLSearchParams, plus JS's URI encoding functions (encodeURIComponent and the others): globals, as in Node; velt/net/url exports them too. For a walkthrough, read the guide.
Exports
decodeURI: like decodeURIComponent, but escapes of ;/?:@&=+$,# stay escaped.decodeURIComponentJS decodeURIComponent; throws URIError("URI malformed") on a bad escape or invalid UTF-8.encodeURIJS encodeURI: like encodeURIComponent, but keeps ;,/?:@&=+$#.encodeURIComponentJS encodeURIComponent: escapes everything except alphanumerics and -_.!~*'(); throws URIError("URI malformed") on a lone surrogate, as JS.UrlErrorThrown for invalid URLs (Invalid URL: <input>, Invalid base URL: <base>): a TypeError, as in JS.URLSearchParamsAn ordered list of name/value pairs in application/x-www-form-urlencoded form (JS URLSearchParams).URLA parsed absolute URL (JS URL).Re-exported from velt/net/url/uri
function decodeURI(s: string): stringJS decodeURI: like decodeURIComponent, but escapes of ;/?:@&=+$,# stay escaped.
Re-exported from velt/net/url/uri
function decodeURIComponent(s: string): stringJS decodeURIComponent; throws URIError("URI malformed") on a bad escape or invalid UTF-8.
Re-exported from velt/net/url/uri
function encodeURI(s: string): stringJS encodeURI: like encodeURIComponent, but keeps ;,/?:@&=+$#.
Re-exported from velt/net/url/uri
function encodeURIComponent(s: string): stringJS encodeURIComponent: escapes everything except alphanumerics and -_.!~*'(); throws
URIError("URI malformed") on a lone surrogate, as JS.
Re-exported from velt/net/url/errors
class UrlError extends TypeErrorThrown for invalid URLs (Invalid URL: <input>, Invalid base URL: <base>): a TypeError, as
in JS. The URI functions throw the prelude's URIError (URI malformed).
Re-exported from velt/net/url/search_params
An ordered list of name/value pairs in application/x-www-form-urlencoded form (JS
URLSearchParams). Names may repeat; order is kept.
Parameter ofURL.searchParamsReturned byURL.searchParamsUsed byvelt/net/httpBodyInit
constructor(init: string = "")Parses a query string (a leading ? is skipped; + means space; bad escapes stay literal).
get size(): usizeNumber of pairs.
get(name: string): string | nullThe first value for name, or null.
getAll(name: string): string[]Every value for name, in order.
has(name: string, value: string | null = null): boolWhether a pair named name (with value value, if given) exists.
append(name: string, value: string)Adds a pair at the end.
set(name: string, value: string)Sets the first pair named name to value and removes the others (appends if none).
delete(name: string, value: string | null = null)Removes every pair named name (with value value, if given).
sort()Stable sort by name, in UTF-16 code-unit order as in JS.
keys(): string[]The names, in order (repeats included).
values(): string[]The values, in order.
entries(): [string, string][][name, value] pairs, in order.
toString(): stringa=1&b=x+y (form encoding: space as +, everything but *-._ and alphanumerics escaped).
Re-exported from velt/net/url/url
A parsed absolute URL (JS URL).
Parameter ofvelt/net/httpfetchRequest.constructor
constructor(input: string, base: string | null = null)Parses input, resolved against base when it is relative; throws UrlError.
static parse(input: string, base: string | null = null): URL | nullLike the constructor, but null instead of throwing (JS URL.parse).
static canParse(input: string, base: string | null = null): boolWhether new URL(input, base) would succeed.
get href(): stringThe whole URL; assigning reparses it (throws UrlError if invalid).
set href(v: string)No doc comment yetget protocol(): stringThe scheme with its colon, e.g. https:.
set protocol(value: string)Switches between schemes of the same kind (special or not), like JS.
get username(): stringPercent-encoded user name ("" if none).
set username(v: string)No doc comment yetget password(): stringPercent-encoded password ("" if none).
set password(v: string)No doc comment yetget host(): stringhostname:port, or just the hostname when the port is absent or the scheme's default.
set host(v: string)Takes the host (and a port after :) up to the first /, ? or #; ignored when the
host is invalid, or empty where the URL needs one (a special scheme, credentials or a port).
An empty port keeps the current one.
get hostname(): stringThe host without the port (lowercased for special schemes; IPv6 keeps its brackets).
set hostname(v: string)Like host, but a value with a port (h:8) is ignored.
get port(): stringThe port as written ("" when absent or the scheme's default, e.g. 443 for https).
set port(value: string)Takes the leading digits of value ("" clears the port); ignored when out of range or when
the URL cannot have a port (no host, or file:).
get pathname(): stringThe path, e.g. /a/b (percent-encoded; for mailto:x it is x).
set pathname(v: string)No doc comment yetget search(): string? + the query, or "" when the query is absent or empty.
set search(v: string)No doc comment yetget hash(): string# + the fragment, or "" when it is absent or empty.
set hash(v: string)No doc comment yetget origin(): stringscheme://host[:port] for http(s), ws(s) and ftp; "null" for other schemes (JS).
get searchParams(): URLSearchParamsA copy of the parsed query (see the header for how to write it back).
set searchParams(p: URLSearchParams)Replaces the query with p serialized (no query if p is empty).
toString(): stringSame as href.
toJSON(): stringSame as href (JS toJSON).