thesis v0.3.4 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

Returns the data type for the provided data using guard functions

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"
iex> parameterize(:this_is_a_test)
"this-is-a-test"
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

Shorthand to_string.

iex> import Thesis.Utilities
iex> to_s(000001)
"1"
iex> to_s(123)
"123"

Returns the data type for the provided data using guard functions.

iex> import Thesis.Utilities
iex> typeof(000001)
"integer"
iex> typeof([1,2,3])
"list"