conv_case v0.2.1 ConvCase View Source

Functions to convert strings, atoms and map keys between camelCase, snake_case and kebab-case.

Currently this functions do not support UTF-8.

Link to this section Summary

Functions

Converts snake_case and kebab-case into camelCase

Converts snake_case and camelCase into kebab-case

Converts camelCase and kebab-case into snake_case

Link to this section Functions

Link to this function to_camel_case(value) View Source
to_camel_case(any()) :: any()

Converts snake_case and kebab-case into camelCase.

For strings, the function returns the converted string.

Examples

iex> ConvCase.to_camel_case("foo_bar")
"fooBar"

iex> ConvCase.to_camel_case("foo-bar")
"fooBar"

For atoms, the function returns the converted atom. This function used String.to_existing_atom/1.

Examples

iex> ConvCase.to_camel_case(:foo_bar)
:fooBar

For lists, the function returns a list with converted values.

Examples

iex> ConvCase.to_camel_case(["foo_bar", "foo-bar"])
["fooBar", "fooBar"]

For maps, the function returns a map with converted keys. The type of the key will not be changed. New atoms are generated by String.to_existing_atom/1. Keys of nested maps are converted too.

Examples

iex> ConvCase.to_camel_case(%{foo_bar: %{"foo-bar" => "foo-bar"}})
%{fooBar: %{"fooBar" => "foo-bar"}}

For other types, the function returns the given value.

Examples

iex> ConvCase.to_camel_case(42)
42
Link to this function to_kebab_case(value) View Source
to_kebab_case(any()) :: any()

Converts snake_case and camelCase into kebab-case.

For strings, the function returns the converted string.

Examples

iex> ConvCase.to_kebab_case("foo_bar")
"foo-bar"

iex> ConvCase.to_kebab_case("fooBar")
"foo-bar"

For atoms, the function returns the converted atom. This function used String.to_existing_atom/1.

Examples

iex> ConvCase.to_kebab_case(:foo_bar)
:"foo-bar"

For lists, the function returns a list with converted values.

Examples

iex> ConvCase.to_kebab_case(["foo_bar", "fooBar"])
["foo-bar", "foo-bar"]

For maps, the function returns a map with converted keys. The type of the key will not be changed. New atoms are generated by String.to_existing_atom/1. Keys of nested maps are converted too.

Examples

iex> ConvCase.to_kebab_case(%{foo_bar: %{"fooBar" => "fooBar"}})
%{"foo-bar": %{"foo-bar" => "fooBar"}}

For other types, the function returns the given value.

Examples

iex> ConvCase.to_kebab_case(42)
42
Link to this function to_snake_case(string) View Source
to_snake_case(any()) :: any()

Converts camelCase and kebab-case into snake_case.

For strings, the function returns the converted string.

Examples

iex> ConvCase.to_snake_case("fooBar")
"foo_bar"

iex> ConvCase.to_snake_case("foo-bar")
"foo_bar"

For atoms, the function returns the converted atom. This function used String.to_existing_atom/1.

Examples

iex> ConvCase.to_snake_case(:fooBar)
:foo_bar

For lists, the function returns a list with converted values.

Examples

iex> ConvCase.to_snake_case(["fooBar", "foo-bar"])
["foo_bar", "foo_bar"]

For maps, the function returns a map with converted keys. The type of the key will not be changed. New atoms are generated by String.to_existing_atom/1. Keys of nested maps are converted too.

Examples

iex> ConvCase.to_snake_case(%{fooBar: %{"foo-bar" => "foo-bar"}})
%{foo_bar: %{"foo_bar" => "foo-bar"}}

For other types, the function returns the given value.

Examples

iex> ConvCase.to_snake_case(42)
42