Norma

Hex.pmHex.pmHex.pmMaintenanceGitHub issuesTravis

Normalize URLs to the format you need.

Installation

Add Norma to your list of dependencies in mix.exs:

def deps do
  [
    # get always the latest ñ___ñ
    {:norma, ">= 0.0.0"}
  ]
end

Note on compatibility

Norma depends heavily on the implementation of the URI module (part of the standard library), which was recently changed when adding support for Erlang 20. Use the module history as a guide if you encounter any weird error (specially if you suspect it’s related to a regex).

Usage

iex> Norma.normalize("mazing.studio")
> "http://mazing.studio"

iex> Norma.normalize_if_valid("mazing.studio")
> {:ok, "http://mazing.studio"}

iex> Norma.normalize_if_valid("mazing")
> {:error, "Not an URL."}

iex> options = %{remove_fragment: true, force_root_path: true, remove_www: true}
iex> Norma.normalize("//www.mazing.studio:1337/test#test", options)
> "http://mazing.studio/"

Options