View Source MacroX (CommonX v0.6.0)
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.
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.
Alias for snakize/1
.
Link to this section Functions
Properly converts atoms and strings to camelCase.
Unlike MacroX.camelize/1
, which converts only strings to PascalCase.
examples
Examples
iex> MacroX.camelize(:my_atom)
:myAtom
iex> MacroX.camelize("my_string")
"myString"
iex> MacroX.camelize("my_ip_address")
"myIPAddress"
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
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"
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
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"
Alias for snakize/1
.
example
Example
iex> MacroX.underscore("PascalCase")
"pascal_case"