DarkMatter.Inflections (DarkMatter v1.1.4) View Source

General utils for working with case conversions.

Link to this section Summary

Types

Available inflection conversions

Functions

Returns the camel case version of the string

Returns the pascal case version of the string

Converts either an atom or string to an atom based on the conversion.

Converts either an atom or string to a string based on the conversion.

Returns the pascal case version of the string

Returns the upper case version of the string

Returns the humanized case version of the string

Returns the camel case version of the string

Returns the plural version of the string

Returns the singluar version of the string

Returns the titleize case version of the string

Returns the underscore version of the string

Link to this section Types

Specs

conversion() ::
  :camel
  | :human
  | :title
  | :pascal
  | :plural
  | :singular
  | :constant
  | :underscore
  | :absinthe_camel
  | :absinthe_pascal

Available inflection conversions

Link to this section Functions

Link to this function

absinthe_camelize(binary)

View Source

Specs

absinthe_camelize(String.t()) :: String.t()

Returns the camel case version of the string

Examples

iex> absinthe_camelize("foo_bar")
"fooBar"

iex> absinthe_camelize("foo")
"foo"

iex> absinthe_camelize("__foo_bar")
"__fooBar"

iex> absinthe_camelize("__foo")
"__foo"

iex> absinthe_camelize("_foo")
"_foo"
Link to this function

absinthe_pascalize(binary)

View Source

Specs

absinthe_pascalize(String.t()) :: String.t()

Returns the pascal case version of the string

Examples

iex> absinthe_pascalize("foo_bar")
"FooBar"

iex> absinthe_pascalize("foo")
"Foo"

iex> absinthe_pascalize("__foo_bar")
"__FooBar"

iex> absinthe_pascalize("__foo")
"__Foo"

iex> absinthe_pascalize("_foo")
"_Foo"
Link to this function

atom(atom_or_binary, conversion_or_conversions)

View Source

Specs

atom(atom() | String.t(), conversion() | [conversion(), ...]) :: atom()

Converts either an atom or string to an atom based on the conversion.

Examples

iex> atom("_foo_bar123XYZ", :absinthe_camel)
:_fooBar123XYZ

iex> atom(:fooBarz___test, :camel)
:fooBarzTest
Link to this function

binary(binary, conversion_or_conversions)

View Source

Specs

binary(atom() | String.t(), conversion() | [conversion(), ...]) :: String.t()

Converts either an atom or string to a string based on the conversion.

Examples

iex> binary("_foo_bar123XYZ", :absinthe_pascal)
"_FooBar123XYZ"

iex> binary("_foo_bar123XYZ", :absinthe_camel)
"_fooBar123XYZ"

iex> binary(:fooBarz___TESTPDF, :pascal)
"FooBarzTestpdf"

iex> binary(:fooBarz___TESTPDF, :camel)
"fooBarzTestpdf"

iex> binary(:HTTP_PdfTEST, :underscore)
"http_pdf_test"

iex> binary("buses", :singular)
"bus"

iex> binary("business", :plural)
"businesses"

iex> binary("MerchantBusiness", [:plural, :underscore])
"merchant_businesses"

Specs

camelize(String.t()) :: String.t()

Returns the pascal case version of the string

Examples

iex> camelize("foo_bar")
"fooBar"

iex> camelize("foo")
"foo"

iex> camelize("__foo_bar")
"fooBar"

iex> camelize("__foo")
"foo"

iex> camelize("_foo")
"foo"

Specs

constantize(String.t()) :: String.t()

Returns the upper case version of the string

Examples

iex> constantize("foo_bar")
"FOO_BAR"

iex> constantize("foo")
"FOO"

iex> constantize("__foo_bar")
"FOO_BAR"

iex> constantize("__foo")
"FOO"

iex> constantize("_foo")
"FOO"

Specs

humanize(String.t()) :: String.t()

Returns the humanized case version of the string

Examples

iex> humanize("foo_bar")
"Foo bar"

iex> humanize("foo")
"Foo"

iex> humanize("__foo_bar")
"  foo bar"

iex> humanize("__foo")
"  foo"

iex> humanize("_foo")
" foo"

Specs

pascalize(String.t()) :: String.t()

Returns the camel case version of the string

Examples

iex> pascalize("foo_bar")
"FooBar"

iex> pascalize("foo")
"Foo"

iex> pascalize("__foo_bar")
"FooBar"

iex> pascalize("__foo")
"Foo"

iex> pascalize("_foo")
"Foo"

Specs

pluralize(String.t()) :: String.t()

Returns the plural version of the string

Examples

iex> pluralize("dog")
"dogs"

iex> pluralize("person")
"people"

Specs

singularize(String.t()) :: String.t()

Returns the singluar version of the string

Examples

With an uppercase first letter:

iex> singularize("dogs")
"dog"

iex> singularize("people")
"person"

Specs

titleize(String.t()) :: String.t()

Returns the titleize case version of the string

Examples

iex> titleize("foo_bar")
"Foo Bar"

iex> titleize("foo")
"Foo"

iex> titleize("__foo_bar")
"Foo Bar"

iex> titleize("__foo")
"Foo"

iex> titleize("_foo")
"Foo"

Specs

underscore(String.t()) :: String.t()

Returns the underscore version of the string

Examples

iex> underscore("UpperCamelCase")
"upper_camel_case"

iex> underscore("pascalCase")
"pascal_case"