Packages
playwrightais
1.32.1-rc
Playwright is an Elixir library to automate Chromium, Firefox and WebKit browsers with a single API. Playwright delivers automation that is ever-green, capable, reliable and fast.
Current section
Files
Jump to
Current section
Files
lib/playwright/helpers/url_matcher.ex
defmodule Playwright.Helpers.URLMatcher do
@moduledoc false
defstruct([:match, :regex])
def new(base_url, match) do
new(Enum.join([base_url, match], "/"))
end
def new(match) do
%__MODULE__{
match: match,
regex: Regex.compile!(translate(match))
}
end
# ---
def matches(%__MODULE__{} = instance, url) do
String.match?(url, instance.regex)
end
# private
# ---------------------------------------------------------------------------
# WARN: `translate` implementations are super naĆÆve at the moment...
# "**" -> ".*"
defp translate(pattern) do
String.replace(pattern, ~r/\*{2,}/, ".*")
end
end