mandarin v0.3.0 Mandarin.Naming

Conveniences for inflecting and working with names in Mandarin.

Link to this section Summary

Functions

Converts String to camel case

Converts an attribute/form field into its humanize version

Extracts the resource name from an alias

Converts String to underscore case

Removes the given suffix from the name if it exists

Link to this section Functions

Link to this function camelize(value)
camelize(String.t()) :: String.t()

Converts String to camel case.

Takes an optional :lower option to return lowerCamelCase.

Examples

iex> Mandarin.Naming.camelize("my_app")
"MyApp"

iex> Mandarin.Naming.camelize("my_app", :lower)
"myApp"

In general, camelize can be thought of as the reverse of underscore, however, in some cases formatting may be lost:

Mandarin.Naming.underscore "SAPExample"  #=> "sap_example"
Mandarin.Naming.camelize   "sap_example" #=> "SapExample"
Link to this function camelize(value, atom)
camelize(String.t(), :lower) :: String.t()
Link to this function humanize(atom)
humanize(atom() | String.t()) :: String.t()

Converts an attribute/form field into its humanize version.

iex> Mandarin.Naming.humanize(:username)
"Username"
iex> Mandarin.Naming.humanize(:created_at)
"Created at"
iex> Mandarin.Naming.humanize("user_id")
"User"
Link to this function resource_name(alias, suffix \\ "")
resource_name(String.Chars.t(), String.t()) :: String.t()

Extracts the resource name from an alias.

Examples

iex> Mandarin.Naming.resource_name(MyApp.User)
"user"

iex> Mandarin.Naming.resource_name(MyApp.UserView, "View")
"user"
Link to this function underscore(value)
underscore(String.t()) :: String.t()

Converts String to underscore case.

Examples

iex> Mandarin.Naming.underscore("MyApp")
"my_app"

In general, underscore can be thought of as the reverse of camelize, however, in some cases formatting may be lost:

Mandarin.Naming.underscore "SAPExample"  #=> "sap_example"
Mandarin.Naming.camelize   "sap_example" #=> "SapExample"
Link to this function unsuffix(value, suffix)
unsuffix(String.t(), String.t()) :: String.t()

Removes the given suffix from the name if it exists.

Examples

iex> Mandarin.Naming.unsuffix("MyApp.User", "View")
"MyApp.User"

iex> Mandarin.Naming.unsuffix("MyApp.UserView", "View")
"MyApp.User"