Combo.Naming (combo v0.10.0)

View Source

Conveniences for working with names.

Summary

Functions

Converts a string to camel case.

Converts an attribute/form field into its humanize version.

Extracts the resource name from an alias.

Converts a string to underscore case.

Removes the given suffix from the name if it exists.

Functions

camelize(value)

@spec camelize(String.t()) :: String.t()

Converts a string to camel case.

Takes an optional :lower flag to return lowerCamelCase.

Examples

iex> Combo.Naming.camelize("demo_app")
"DemoApp"

iex> Combo.Naming.camelize("demo_app", :lower)
"demoApp"

Note

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

Combo.Naming.underscore("SAPExample")  #=> "sap_example"
Combo.Naming.camelize("sap_example")   #=> "SapExample"

camelize(value, atom)

@spec camelize(String.t(), :lower) :: String.t()

humanize(atom)

@spec humanize(atom() | String.t()) :: String.t()

Converts an attribute/form field into its humanize version.

Examples

iex> Combo.Naming.humanize(:username)
"Username"

iex> Combo.Naming.humanize(:created_at)
"Created at"

iex> Combo.Naming.humanize("user_id")
"User"

resource_name(alias, suffix \\ "")

@spec resource_name(String.Chars.t(), String.t()) :: String.t()

Extracts the resource name from an alias.

Examples

iex> Combo.Naming.resource_name(Demo.Core.User)
"user"

iex> Combo.Naming.resource_name(Demo.Web.UserHTML, "HTML")
"user"

underscore(value)

@spec underscore(String.t()) :: String.t()

Converts a string to underscore case.

Examples

iex> Combo.Naming.underscore("DemoApp")
"demo_app"

Note

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

Combo.Naming.underscore("SAPExample")  #=> "sap_example"
Combo.Naming.camelize("sap_example")   #=> "SapExample"

unsuffix(value, suffix)

@spec unsuffix(String.t(), String.t()) :: String.t()

Removes the given suffix from the name if it exists.

Examples

iex> Combo.Naming.unsuffix("Demo.Core.User", "HTML")
"Demo.Core.User"

iex> Combo.Naming.unsuffix("Demo.Web.UserHTML", "HTML")
"Demo.Web.User"