Expand description
The legacy url.parse / url.format API — a faithful port of Node’s
lib/url.js Url.prototype.parse, Url.prototype.format and urlFormat.
This API predates (and disagrees with) the WHATWG URL parser in url.rs:
it is a hand-rolled scanner with its own whitespace trimming, backslash
rewriting, “simple path” fast path, auto-escaping table and slashed/hostless
protocol sets. Reimplementing it from the documentation produces a parser
that agrees on http://host/path and disagrees on everything else, so this
is a line-for-line port of the JS instead, sharing the same field names and
insertion order (protocol, slashes, auth, host, port, hostname, hash, search, query, pathname, path, href).
Node scans by UTF-16 code unit; this port scans by char. Every branch keys
off ASCII delimiters, so the emitted strings match.
Structs§
- Url
- The parsed legacy URL. Every field is
Option, mirroring thenull-initializedUrlinstance;slashesis a tri-state (None=null).
Functions§
- format_
url - Port of
Url.prototype.format.query_stringis the already-stringifiedqueryobject (Node runsquerystring.stringifywhenqueryis an object);Nonemeansquerywas not an object. - format_
value url.format(urlObject)— a string is re-parsed first, aURLinstance uses itshref, and anything else goes throughUrl.prototype.format.- parse
- Port of
Url.prototype.parse.slashes_denote_hostis the thirdurl.parseargument. Errors correspond to the JSthrowsites. - to_js
- Build the JS
Url-shaped object, preserving Node’s field insertion order.