thesis v0.0.29 Thesis.Utilities

Module that provides helper functions.

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

Functions

normalize_url(url)

Takes a URL and strips unnecessary characters.

iex> import Thesis.Utilities
iex> normalize_url("http://infinite.red//ignite//foo")
"http://infinite.red/ignite/foo"
iex> normalize_url("https://infinite.red/ignite/foo/")
"https://infinite.red/ignite/foo"
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"
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
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