View Source ExToolkit.Naming (ExToolkit v0.9.13)

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.

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.

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

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

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

Functions

capitalize(name)

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

Capitalizes the first letter of each word in a name.

Arguments

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

Examples

iex> Naming.capitalize(nil)
""

iex> Naming.capitalize("")
""

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

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

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

extract_first_last_name(name)

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

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

Arguments

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

Examples

iex> Naming.extract_first_last_name(nil)
""

iex> Naming.extract_first_last_name("")
""

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

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

extract_initials(name)

@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.

Arguments

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

Examples

iex> Naming.extract_initials(nil)
""

iex> Naming.extract_initials("")
""

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

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

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

extract_short_name(name)

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

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

Arguments

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

Examples

iex> Naming.extract_short_name(nil)
""

iex> Naming.extract_short_name("")
""

iex> Naming.extract_short_name("john")
"John"

iex> Naming.extract_short_name("john doe smith")
"J. Smith"

iex> Naming.extract_short_name("john doe smith (funny)")
"J. Smith"

shorten_firstname(name)

@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.

Arguments

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

Examples

iex> Naming.shorten_firstname(nil)
""

iex> Naming.shorten_firstname("")
""

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

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

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

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

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

shorten_lastname(name)

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

Shortens the last 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 last name to its initial. The rest of the name is preserved. The initial is followed by a period and a space.

Arguments

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

Examples

iex> Naming.shorten_lastname(nil)
""

iex> Naming.shorten_lastname("")
""

iex> Naming.shorten_lastname("John")
"John"

iex> Naming.shorten_lastname("john")
"John"

iex> Naming.shorten_lastname("John Doe")
"John D."

iex> Naming.shorten_lastname("John Van Doe")
"John Van D."

iex> Naming.shorten_lastname("john doe")
"John D."