gossamer/url

Types

A parsed URL. Mutable — setters like set_hostname modify the URL in place and return it for chaining.

See URL on MDN.

pub type URL

Values

pub fn can_parse(url: String) -> Bool
pub fn can_parse_with_base(
  url: String,
  relative_to base: String,
) -> Bool
pub fn create_object_url(blob: blob.Blob) -> String

Creates a string containing a URL representing the given blob. The URL lifetime is tied to the document or worker that created it.

pub fn hash(of url: URL) -> String
pub fn host(of url: URL) -> String
pub fn hostname(of url: URL) -> String
pub fn href(of url: URL) -> String
pub fn new(url: String) -> Result(URL, js_error.JsError)

Parses url into a URL. Returns an error if the string is not a valid absolute URL.

pub fn new_with_base(
  url: String,
  relative_to base: String,
) -> Result(URL, js_error.JsError)

Parses url, resolving relative URLs against base. Returns an error if the resolved URL is invalid.

pub fn origin(of url: URL) -> String
pub fn parse(url: String) -> Result(URL, Nil)

Like new, but returns Error(Nil) rather than a JsError when the URL is invalid.

pub fn parse_with_base(
  url: String,
  relative_to base: String,
) -> Result(URL, Nil)

Like new_with_base, but returns Error(Nil) rather than a JsError when the URL is invalid.

pub fn password(of url: URL) -> String
pub fn pathname(of url: URL) -> String
pub fn port(of url: URL) -> String
pub fn protocol(of url: URL) -> String
pub fn revoke_object_url(url: String) -> Nil

Revokes an object URL previously created with create_object_url. Call this to release the reference once the URL is no longer needed.

pub fn search(of url: URL) -> String
pub fn set_hash(of url: URL, to hash: String) -> URL
pub fn set_host(of url: URL, to host: String) -> URL
pub fn set_hostname(of url: URL, to hostname: String) -> URL
pub fn set_href(
  of url: URL,
  to href: String,
) -> Result(URL, js_error.JsError)

Sets the full URL string, reparsing it. Returns an error if the new href is not a valid URL.

pub fn set_password(of url: URL, to password: String) -> URL
pub fn set_pathname(of url: URL, to pathname: String) -> URL
pub fn set_port(of url: URL, to port: String) -> URL
pub fn set_protocol(of url: URL, to protocol: String) -> URL
pub fn set_search(of url: URL, to search: String) -> URL
pub fn set_username(of url: URL, to username: String) -> URL
pub fn to_json(url: URL) -> String
pub fn to_string(url: URL) -> String
pub fn username(of url: URL) -> String
Search Document