CommonX v0.0.5 MacroX View Source

Macro extension module.

Link to this section Summary

Functions

Properly converts atoms and strings to camelCase. Unlike MacroX.camelize/1, which converts only strings to PascalCase

Converts the given string to PascalCase format. This function was designed to pascalize language identifiers/tokens, that's why it belongs to the MacroX module. Do not use it as a general mechanism for pascalizing strings as it does not support Unicode or characters that are not valid in Elixir identifiers.

Examples

Converts the given atom or binary to snakize format. If an atom is given, it is assumed to be an Elixir module, so it is converted to a binary and then processed. This function was designed to snakize language identifiers/tokens, that's why it belongs to the Macro module. Do not use it as a general mechanism for underscoring strings as it does not support Unicode or characters that are not valid in Elixir identifiers.

Examples

Link to this section Functions

Link to this function

camelize(h) View Source
camelize(atom() | String.t()) :: atom() | String.t()

Properly converts atoms and strings to camelCase. Unlike MacroX.camelize/1, which converts only strings to PascalCase.

Examples

iex> MacroX.camelize(:my_atom)
:myAtom

iex> MacroX.camelize("my_string")
"myString"

iex> MacroX.camelize("my_ip_address")
"myIPAddress"
Link to this function

pascalize(data) View Source
pascalize(String.t() | atom()) :: String.t() | atom()

Converts the given string to PascalCase format. This function was designed to pascalize language identifiers/tokens, that's why it belongs to the MacroX module. Do not use it as a general mechanism for pascalizing strings as it does not support Unicode or characters that are not valid in Elixir identifiers.

Examples

iex> MacroX.pascalize("foo_bar")
"FooBar"
iex> MacroX.pascalize(:foo_bar)
FooBar
iex> MacroX.pascalize("cluster_ip")
"ClusterIP"

If uppercase characters are present, they are not modified in any way as a mechanism to preserve acronyms:

iex> MacroX.pascalize("API.V1")
"API.V1"
iex> MacroX.pascalize("API_SPEC")
"API_SPEC"
Link to this function

snakize(atom) View Source
snakize(String.t() | atom()) :: String.t() | atom()

Converts the given atom or binary to snakize format. If an atom is given, it is assumed to be an Elixir module, so it is converted to a binary and then processed. This function was designed to snakize language identifiers/tokens, that's why it belongs to the Macro module. Do not use it as a general mechanism for underscoring strings as it does not support Unicode or characters that are not valid in Elixir identifiers.

Examples

iex> MacroX.snakize("FooBar")
"foo_bar"
iex> MacroX.snakize("Foo.Bar")
"foo/bar"
iex> MacroX.snakize(Foo.Bar)
"foo/bar"
iex> MacroX.snakize(:FooBar)
:foo_bar

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

iex> MacroX.snakize("SAPExample")
"sap_example"
iex> MacroX.pascalize("sap_example")
"SapExample"
iex> MacroX.pascalize("hello_10")
"Hello10"
Link to this function

underscore(data) View Source
underscore(String.t() | atom()) :: String.t() | atom()

Alias for snakize/1.

Example

iex> MacroX.underscore("PascalCase")
"pascal_case"