case2 v0.1.3 Case2 View Source

Case2 is a handy utility to transform case of strings.

Link to this section Summary

Functions

Splits the input and rejoins it with a separator given. Optionally converts parts to downcase, upcase or titlecase

Splits the input into list. Utility function

Converts the input to camel case

Converts the input to constant case

Converts the input to dot case

Converts the input to kebab case

Converts the input to pascal case

Converts the input to path case

Converts the input to sentence case

Converts the input to snake case. Alias: underscore

Converts the input to title case

Link to this section Functions

Link to this function

rejoin(input, opts \\ []) View Source
rejoin(input :: String.t(), opts :: Keyword.t()) :: String.t()

Splits the input and rejoins it with a separator given. Optionally converts parts to downcase, upcase or titlecase.

  • opts[:case] :: [:down | :up | :title | :none]
  • opts[:separator] :: binary() | integer()

Default separator is ?_, default conversion is :downcase so that it behaves the same way as to_snake/1.

Examples

iex> Case2.rejoin "foo_barBaz-λambdaΛambda-привет-Мир", separator: "__"
"foo__bar__baz__λambda__λambda__привет__мир"
Link to this function

split(input) View Source
split(input :: String.t()) :: [String.t()]

Splits the input into list. Utility function.

Examples

iex> Case2.split "foo_barBaz-λambdaΛambda-привет-Мир"
["foo", "bar", "Baz", "λambda", "Λambda", "привет", "Мир"]
Link to this function

to_camel(input) View Source
to_camel(input :: String.t()) :: String.t()

Converts the input to camel case.

Examples

iex> Case2.to_camel "foo_barBaz-λambdaΛambda-привет-Мир"
"fooBarBazΛambdaΛambdaПриветМир"

Read about camelCase here: https://en.wikipedia.org/wiki/Camel_case

Link to this function

to_constant(input) View Source
to_constant(input :: String.t()) :: String.t()

Converts the input to constant case.

Examples

iex> Case2.to_constant "foo_barBaz-λambdaΛambda-привет-Мир"
"FOO_BAR_BAZ_ΛAMBDA_ΛAMBDA_ПРИВЕТ_МИР"
Link to this function

to_dot(input) View Source
to_dot(input :: String.t()) :: String.t()

Converts the input to dot case.

Examples

iex> Case2.to_dot "foo_barBaz-λambdaΛambda-привет-Мир"
"foo.bar.baz.λambda.λambda.привет.мир"
Link to this function

to_kebab(input) View Source
to_kebab(input :: String.t()) :: String.t()

Converts the input to kebab case.

Examples

iex> Case2.to_kebab "foo_barBaz-λambdaΛambda-привет-Мир"
"foo-bar-baz-λambda-λambda-привет-мир"
Link to this function

to_pascal(input) View Source
to_pascal(input :: String.t()) :: String.t()

Converts the input to pascal case.

Examples

iex> Case2.to_pascal "foo_barBaz-λambdaΛambda-привет-Мир"
"FooBarBazΛambdaΛambdaПриветМир"
Link to this function

to_path(input) View Source
to_path(input :: String.t()) :: String.t()

Converts the input to path case.

Examples

iex> Case2.to_path "foo_barBaz-λambdaΛambda-привет-Мир"
"foo/bar/Baz/λambda/Λambda/привет/Мир"
Link to this function

to_sentence(input) View Source
to_sentence(input :: String.t()) :: String.t()

Converts the input to sentence case.

Read about Sentence case here: https://en.wikipedia.org/wiki/Letter_case#Sentence_case

Examples

iex> Case2.to_sentence "foo_barBaz-λambdaΛambda-привет-Мир"
"Foo bar baz λambda λambda привет мир"
Link to this function

to_snake(input) View Source
to_snake(input :: String.t()) :: String.t()

Converts the input to snake case. Alias: underscore.

Examples

iex> Case2.to_snake "foo_barBaz-λambdaΛambda-привет-Мир"
"foo_bar_baz_λambda_λambda_привет_мир"
iex> Case2.underscore "foo_barBaz-λambdaΛambda-привет-Мир"
"foo_bar_baz_λambda_λambda_привет_мир"
Link to this function

to_title(input) View Source
to_title(input :: String.t()) :: String.t()

Converts the input to title case.

Read about Sentence case here: https://en.wikipedia.org/wiki/Letter_case#Title_case

NB! at the moment has no stop words: titleizes everything

Examples

iex> Case2.to_title "foo_barBaz-λambdaΛambda-привет-Мир"
"Foo Bar Baz Λambda Λambda Привет Мир"