gossamer/url_pattern

Types

pub type Fields {
  Fields(
    protocol: String,
    username: String,
    password: String,
    hostname: String,
    port: String,
    pathname: String,
    search: String,
    hash: String,
    has_reg_exp_groups: Bool,
  )
}

Constructors

  • Fields(
      protocol: String,
      username: String,
      password: String,
      hostname: String,
      port: String,
      pathname: String,
      search: String,
      hash: String,
      has_reg_exp_groups: Bool,
    )

A pattern for matching URLs, with support for wildcards and named groups. Useful for routing and URL matching.

See URLPattern on MDN.

pub type URLPattern
pub type URLPatternComponentResult {
  URLPatternComponentResult(
    input: String,
    groups: dict.Dict(String, String),
  )
}

Constructors

  • URLPatternComponentResult(
      input: String,
      groups: dict.Dict(String, String),
    )
pub type URLPatternInit {
  Protocol(String)
  Username(String)
  Password(String)
  Hostname(String)
  Port(String)
  Pathname(String)
  Search(String)
  Hash(String)
  BaseURL(String)
}

Constructors

  • Protocol(String)
  • Username(String)
  • Password(String)
  • Hostname(String)
  • Port(String)
  • Pathname(String)
  • Search(String)
  • Hash(String)
  • BaseURL(String)

Values

pub fn exec(
  pattern: URLPattern,
  against input: String,
) -> Result(URLPatternResult, Nil)

Matches input against the pattern and returns the captured components, or Error(Nil) if there is no match.

pub fn exec_with_base(
  pattern: URLPattern,
  against input: String,
  relative_to base_url: String,
) -> Result(URLPatternResult, Nil)

Like exec, but resolves input against base_url before matching. Returns Error(Nil) if there is no match or base_url is not a valid URL.

pub fn from_string(
  pattern: String,
) -> Result(URLPattern, js_error.JsError)

Creates a URLPattern from a single pattern string. Returns an error if the pattern is malformed.

pub fn from_string_with_base(
  pattern: String,
  relative_to base_url: String,
) -> Result(URLPattern, js_error.JsError)

Creates a URLPattern from a pattern string resolved against a base URL. Returns an error if the pattern is malformed or the base URL is invalid.

pub fn has_reg_exp_groups(pattern: URLPattern) -> Bool
pub fn hash(of pattern: URLPattern) -> String
pub fn hostname(of pattern: URLPattern) -> String
pub fn new(
  init: List(URLPatternInit),
) -> Result(URLPattern, js_error.JsError)

Creates a URLPattern from per-component patterns. Returns an error if any pattern is malformed.

pub fn password(of pattern: URLPattern) -> String
pub fn pathname(of pattern: URLPattern) -> String
pub fn port(of pattern: URLPattern) -> String
pub fn protocol(of pattern: URLPattern) -> String
pub fn search(of pattern: URLPattern) -> String
pub fn test_(pattern: URLPattern, against input: String) -> Bool
pub fn test_with_base(
  pattern: URLPattern,
  against input: String,
  relative_to base_url: String,
) -> Bool

Like test, but resolves input against base_url before matching. Returns False if base_url is not a valid URL (the match algorithm returns null rather than throwing).

pub fn to_fields(pattern: URLPattern) -> Fields
pub fn username(of pattern: URLPattern) -> String
Search Document