JediHelpers (jedi_helpers v0.1.1)
Documentation for JediHelpers
.
Summary
Functions
Converts an atom into a human-readable string by title-casing its segments.
Formats a decimal or numeric input by
Formats a user's full name as "First Last"
.
Formats a user's name as "Last, First"
if :last_first
style is passed.
Formats a user's full name with email as "First Last - email@example.com"
.
Returns the underscored (snake_case) name of a struct's module as a string.
Extracts the path segment from a URI string.
Functions
Converts an atom into a human-readable string by title-casing its segments.
Useful for displaying labels or headings derived from atoms.
Examples
iex> JediHelpers.atom_to_readable_string(:user_profile)
"User Profile"
iex> JediHelpers.atom_to_readable_string(:admin)
"Admin"
Formats a decimal or numeric input by:
- Converting it to a
Decimal
- Rounding to 2 decimal places
- Converting to a string
- Adding thousands separators (e.g.,
"1,234.56"
)
Returns nil
if the input is nil
.
Examples
iex> format_decimal(1234567.891)
"1,234,567.89"
iex> format_decimal("1000.1")
"1,000.10"
iex> format_decimal(nil)
nil
Requirements
Requires the :decimal
and :number
libraries.
Formats a user's full name as "First Last"
.
Returns nil
if the input is nil
.
Examples
iex> format_name(%{first_name: "Luke", last_name: "Skywalker"})
"Luke Skywalker"
Formats a user's name as "Last, First"
if :last_first
style is passed.
Examples
iex> format_name(%{first_name: "Luke", last_name: "Skywalker"}, :last_first)
"Skywalker, Luke"
Formats a user's full name with email as "First Last - email@example.com"
.
Examples
iex> format_name_with_email(%{first_name: "Leia", last_name: "Organa", email: "leia@alderaan.com"})
"Leia Organa - leia@alderaan.com"
Returns the underscored (snake_case) name of a struct's module as a string.
Useful for generating type identifiers from structs, especially in APIs or dynamic logic.
Example
iex> resource_type(%JediHelpers.BlogPost{})
"blog_post"
Parameters:
resource
(struct
): Any Elixir struct.
Returns:
String.t()
: The snake_case name of the struct's module (last segment only).
Extracts the path segment from a URI string.
Useful for isolating the path portion of a full URL (e.g. /users/123
).
Example
iex> uri_parse_path("https://example.com/users/123?ref=home")
"/users/123"
Parameters:
uri
(String.t()
): A URI string.
Returns:
String.t()
ornil
: The path component of the URI, ornil
if absent.