Skip to content

Commit

Permalink
feat: Add is_valid_url? function. #64
Browse files Browse the repository at this point in the history
  • Loading branch information
LuchoTurtle committed Nov 10, 2023
1 parent 335303d commit 93b6596
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/useful.ex
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ defmodule Useful do
"#{key}: #{value}"
end

@doc """
`is_valid_url?/1` checks if a string is a valid URL.
"""
def is_valid_url?(string) do
[:scheme, :host, :port]
|> Enum.map(&Map.get(URI.parse(string), &1))
|> Enum.all?()
end

# Recap: https://elixir-lang.org/getting-started/basic-types.html#tuples
defp to_list_of_tuples(map) do
map
Expand Down

0 comments on commit 93b6596

Please sign in to comment.