URL normalization.
Norma parses a URL string and rewrites it into a canonical form,
defaulting the scheme to http and applying the transformations
requested through the options map.
Two entry points are provided:
normalize_if_valid/2— returns{:ok, url}or{:error, reason}.normalize/2— returns the normalized URL, or the input unchanged when it isn't a URL.
See normalize_if_valid/2 for the list of supported options.
Summary
Functions
Similar to normalize_if_valid/2, but will return the given string unchanged
if it's not an URL.
Normalize URL according to the options given.
Defaults scheme to http.
Functions
Similar to normalize_if_valid/2, but will return the given string unchanged
if it's not an URL.
Examples
iex> Norma.normalize!("//www.mazing.studio", %{remove_www: true})
"http://mazing.studio"
Normalize URL according to the options given.
Defaults scheme to http.
Options
remove_fragmentforce_root_pathadd_root_pathadd_trailing_slashremove_wwwremove_schemerestore_old_query_behavior— rebuild the query the 1.x way (keys sorted, duplicate keys collapsed to the last value) instead of preserving input order and duplicates
Host case is always folded to lowercase via RFC 3986 normalization
(:uri_string.normalize/1). The 1.x downcase_host option was removed in 2.0.
Check the README for the full examples.
Examples
iex> Norma.normalize("//www.mazing.studio", %{remove_www: true})
{:ok, "http://mazing.studio"}