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
Alias for snakize/1
Link to this section Functions
camelize(h) View Source
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"
pascalize(data) View Source
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"
snakize(atom) View Source
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"
underscore(data) View Source
Alias for snakize/1
.
Example
iex> MacroX.underscore("PascalCase")
"pascal_case"