ConvCase (hl7 v1.0.1)

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

Currently this functions do not support UTF-8.

If this package fits not your requirements then take a look here:

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.

Functions

Link to this function

to_camel_case(value)

@spec 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 tuples, the function returns a tuple 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)

@spec 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 tuples, the function returns a tuple 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)

@spec 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. String.to_existing_atom/1 is used to create "new" atoms.

iex> ConvCase.to_snake_case(:fooBar)
:foo_bar

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

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

For tuples, the function returns a tuple with converted values.

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. The keys of nested maps are also converted.

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.

iex> ConvCase.to_snake_case(42)
42