View Source Utilx.NamingUtils (Utilx v0.1.2)

This module encapsulates common tasks related to processing personal names in a standardized format. This module treats names as case-insensitive and returns results in a formatted, readable way.

Link to this section Summary

Functions

Capitalizes the first letter of each word in a name.

Extracts and capitalizes the first and last names from a given name.

Extracts the initials from a given name.

Shortens the first name to its initial, while preserving the rest of the name.

Link to this section Functions

@spec capitalize(nil | String.t()) :: String.t()

Capitalizes the first letter of each word in a name.

parameters

Parameters

  • name: A string representing a full name, or nil.

examples

Examples

iex> NamingUtils.capitalize(nil) ""

iex> NamingUtils.capitalize("") ""

iex> NamingUtils.capitalize("john doe") "John Doe"

iex> NamingUtils.capitalize("JOHN DOE") "John Doe"

iex> NamingUtils.capitalize("john nommensen duchac") "John Nommensen Duchac"

Link to this function

extract_first_last_name(name)

View Source
@spec extract_first_last_name(nil | String.t()) :: String.t()

Extracts and capitalizes the first and last names from a given name.

parameters

Parameters

  • name: A string representing a full name, or nil.

examples

Examples

iex> NamingUtils.extract_first_last_name(nil) ""

iex> NamingUtils.extract_first_last_name("") ""

iex> NamingUtils.extract_first_last_name("john") "John"

iex> NamingUtils.extract_first_last_name("john doe smith") "John Smith"

@spec extract_initials(nil | String.t()) :: String.t()

Extracts the initials from a given name.

This function takes a name (a string of one or more words), and extracts the first letter of the first name and the family name.

parameters

Parameters

  • name: A string representing a full name, or nil.

examples

Examples

iex> NamingUtils.extract_initials(nil) ""

iex> NamingUtils.extract_initials("") ""

iex> NamingUtils.extract_initials("John") "J"

iex> NamingUtils.extract_initials("John Doe") "JD"

iex> NamingUtils.extract_initials("John Nommensen Duchac") "JD"

@spec shorten_firstname(nil | String.t()) :: String.t()

Shortens the first name to its initial, while preserving the rest of the name.

This function takes a name (a string of one or more words), and reduces the first name to its initial. The rest of the name is preserved. The initial is followed by a period and a space, and then the rest of the name.

parameters

Parameters

  • name: A string representing a full name, or nil.

examples

Examples

iex> NamingUtils.shorten_firstname(nil) ""

iex> NamingUtils.shorten_firstname("") ""

iex> NamingUtils.shorten_firstname("John") "J."

iex> NamingUtils.shorten_firstname("john") "J."

iex> NamingUtils.shorten_firstname("John Doe") "J. Doe"

iex> NamingUtils.shorten_firstname("john doe") "J. Doe"

iex> NamingUtils.shorten_firstname("john doe jr") "J. Doe Jr"