Packages
drab
0.9.3
0.10.5
0.10.4
0.10.3
0.10.2
0.10.1
0.10.0
0.9.3
0.9.2
0.9.1
0.9.0
0.8.3
0.8.2
0.8.1
0.8.0
0.7.7
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.3
0.6.2
0.6.1
0.6.0
0.6.0-pre.1
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.1
0.1.0
Remote controlled frontend framework for Phoenix.
Current section
Files
Jump to
Current section
Files
lib/drab/coder/url.ex
defmodule Drab.Coder.URL do
@moduledoc false
@invalid_argument {:error, "invalid argument; only string is allowed"}
@spec encode(String.t()) :: Drab.Coder.return()
@doc """
Urlencode given string.
iex> Drab.Coder.URL.encode("test !/ Łódź&?")
{:ok, "test+%21%2F+%C5%81%C3%B3d%C5%BA%26%3F"}
iex> Drab.Coder.URL.encode(42)
{:error, "invalid argument; only string is allowed"}
"""
def encode(string) when is_binary(string), do: {:ok, URI.encode_www_form(string)}
def encode(_), do: @invalid_argument
@spec encode!(String.t()) :: String.t()
@doc """
Urlencode given string.
iex> Drab.Coder.URL.encode!("test !/ Łódź&?")
"test+%21%2F+%C5%81%C3%B3d%C5%BA%26%3F"
"""
defdelegate encode!(string), to: URI, as: :encode_www_form
@spec decode(String.t()) :: Drab.Coder.return()
@doc """
Urldecode the string.
iex> Drab.Coder.URL.decode("test+%21%2F+%C5%81%C3%B3d%C5%BA%26%3F")
{:ok, "test !/ Łódź&?"}
iex> Drab.Coder.URL.decode(42)
{:error, "invalid argument; only string is allowed"}
"""
def decode(string) when is_binary(string), do: {:ok, URI.decode_www_form(string)}
def decode(_), do: @invalid_argument
@spec decode!(String.t()) :: String.t()
@doc """
Urldecode the string.
iex> Drab.Coder.URL.decode!("test+%21%2F+%C5%81%C3%B3d%C5%BA%26%3F")
"test !/ Łódź&?"
"""
defdelegate decode!(string), to: URI, as: :decode_www_form
end