thesis v0.2.0 Thesis.Utilities
Module that provides helper functions.
Link to this section Summary
Functions
Takes a URL and strips unnecessary characters
Removes special characters, keeps dashes and underscores, and replaces spaces with dashes. Also downcases the entire string
Generates a random string of letters of a given length
Generates a random string of digits of a given length
Shorthand to_string
Link to this section Functions
Link to this function
normalize_path(path)
Takes a URL and strips unnecessary characters.
iex> import Thesis.Utilities
iex> normalize_path("//ignite//foo")
"/ignite/foo"
iex> normalize_path("/ignite/foo/")
"/ignite/foo"
iex> normalize_path("/")
"/"
Link to this function
parameterize(str)
Removes special characters, keeps dashes and underscores, and replaces spaces with dashes. Also downcases the entire string.
iex> import Thesis.Utilities
iex> parameterize("Jamon is so cool!")
"jamon-is-so-cool"
iex> parameterize("%#d50SDF dfsJ FDS lkdsf f dfka a")
"d50sdf-dfsj-fds--lkdsf-f-dfka---a"
Link to this function
random_string(length)
Generates a random string of letters of a given length.
iex> import Thesis.Utilities
iex> String.length(random_string(15))
15
iex> random_string(15) != random_string(15)
true
Link to this function
random_string(length, atom)
Generates a random string of digits of a given length.
iex> import Thesis.Utilities
iex> String.length(random_string(15, :numeric))
15
iex> random_string(15, :numeric) != random_string(15, :numeric)
true
iex> String.to_integer(random_string(15, :numeric)) > 0
true
Link to this function
to_s(arg)
Shorthand to_string
.
iex> import Thesis.Utilities
iex> to_s(000001)
"1"
iex> to_s(123)
"123"