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
rejoin(input, opts \\ []) View Source
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__привет__мир"
split(input) View Source
Splits the input into list
. Utility function.
Examples
iex> Case2.split "foo_barBaz-λambdaΛambda-привет-Мир"
["foo", "bar", "Baz", "λambda", "Λambda", "привет", "Мир"]
to_camel(input) View Source
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
to_constant(input) View Source
Converts the input to constant
case.
Examples
iex> Case2.to_constant "foo_barBaz-λambdaΛambda-привет-Мир"
"FOO_BAR_BAZ_ΛAMBDA_ΛAMBDA_ПРИВЕТ_МИР"
to_dot(input) View Source
Converts the input to dot
case.
Examples
iex> Case2.to_dot "foo_barBaz-λambdaΛambda-привет-Мир"
"foo.bar.baz.λambda.λambda.привет.мир"
to_kebab(input) View Source
Converts the input to kebab
case.
Examples
iex> Case2.to_kebab "foo_barBaz-λambdaΛambda-привет-Мир"
"foo-bar-baz-λambda-λambda-привет-мир"
to_pascal(input) View Source
Converts the input to pascal
case.
Examples
iex> Case2.to_pascal "foo_barBaz-λambdaΛambda-привет-Мир"
"FooBarBazΛambdaΛambdaПриветМир"
to_path(input) View Source
Converts the input to path
case.
Examples
iex> Case2.to_path "foo_barBaz-λambdaΛambda-привет-Мир"
"foo/bar/Baz/λambda/Λambda/привет/Мир"
to_sentence(input) View Source
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 привет мир"
to_snake(input) View Source
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_привет_мир"
to_title(input) View Source
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 Привет Мир"