# `Helpers`
[🔗](https://github.com/gtri/lowendinsight/blob/main/lib/helpers.ex#L5)

Collection of generic helper functions.

# `convert_config_to_list`

```elixir
@spec convert_config_to_list([any()]) :: map()
```

convert_config_to_list/1: takes in Application.get_all_env(:app) and returns a list of
maps, to be encoded as JSON.  Since JSON doesn't have an equivalent tuple type the
libs all bonk on encoding config values.

# `count_forward_slashes`

```elixir
@spec count_forward_slashes(String.t()) :: non_neg_integer()
```

# `get_slug`

```elixir
@spec get_slug(String.t()) :: {:ok, String.t()} | {:error, String.t()}
```

get_slug/1: extracts the slug from the provided URI argument and returns the path

# Example
    iex(1)> {:ok, slug} = Helpers.get_slug("https://github.com/kitplummer/xmpprails")
    {:ok, "kitplummer/xmpprails"}
    iex(2)> slug
    "kitplummer/xmpprails"

# `remove_git_prefix`

```elixir
@spec remove_git_prefix(String.t()) :: String.t()
```

remove_git_prefix/1: removes the git+ prefix found in some public Git URLs

# `split_slug`

```elixir
@spec split_slug(String.t()) :: {:ok, String.t(), String.t()} | {:error, String.t()}
```

split_slug/1: splits apart the username and repo from a git slug returning discrete stings.

## Examples

    iex(6)> {:ok, org, repo}  = Helpers.split_slug("kitplummer/xmpprails")
    {:ok, "kitplummer", "xmpprails"}
    iex(7)> org
    "kitplummer"
    iex(8)> repo
    "xmpprails"

# `validate_url`

```elixir
@spec validate_url(String.t()) :: :ok | {:error, String.t()}
```

validate_url/1: validates field is a valid url.

## Examples
    iex> "https:://www.url.com"
    ...> |> Helpers.validate_url()
    {:error, "invalid URI path"}

    iex> "https://github.com/"
    ...> |> Helpers.validate_url()
    :ok

    iex> '"https://"https://www.google.com"'
    ...> |> Helpers.validate_url()
    {:error, "invalid URI"}

    iex> "zipbooks.com"
    ...> |> Helpers.validate_url()
    {:error, "invalid URI"}

    iex> "https://zipbooks..com"
    ...> |> Helpers.validate_url()
    {:error, "invalid URI host"}

# `validate_urls`

```elixir
@spec validate_urls([String.t()]) :: :ok | {:error, String.t()}
```

validate_urls/1: validates a list of urls

## Examples
    iex> ["http://www.google.com","http://www.test.com"]
    ...> |> Helpers.validate_urls()
    :ok

    iex> ["https://zipbooks..com", "http://www.test.com"]
    ...> |> Helpers.validate_urls()
    {:error, %{:message => "invalid URI", :urls => ["https://zipbooks..com"]}}

    iex> ["https//github.com/kitplummer/xmpp4rails","https://www.zipbooks.com", "http://www.test.com"]
    ...> |> Helpers.validate_urls()
    {:error, %{:message => "invalid URI", :urls => ["https//github.com/kitplummer/xmpp4rails"]}}

    iex> "https://zipbooks.com"
    ...> |> Helpers.validate_urls()
    {:error, "invalid URI"}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
