CaseStyle behaviour (case_style v1.0.1)

Library from converting to different CaseSyles

Currently implemented:

Summary

Functions

same as camel_to_kebab but return a string on success and raises on error on failure

same as camel_to_pascal but return a string on success and raises on error on failure

same as camel_to_snake but return a string on success and raises on error on failure

parse given input with the given module

same as graphql_to_snake but return a string on success and raises on error on failure

same as kebab_to_camel but return a string on success and raises on error on failure

same as kebab_to_pascal but return a string on success and raises on error on failure

same as kebab_to_snake but return a string on success and raises on error on failure

same as pascal_to_camel but return a string on success and raises on error on failure

same as pascal_to_kebab but return a string on success and raises on error on failure

same as pascal_to_snake but return a string on success and raises on error on failure

same as snake_to_camel but return a string on success and raises on error on failure

same as snake_to_graphql but return a string on success and raises on error on failure

same as snake_to_kebab but return a string on success and raises on error on failure

same as snake_to_pascal but return a string on success and raises on error on failure

dump given input with the given module

Types

nimble_parsec_error()

@type nimble_parsec_error() ::
  {:error, binary(), binary(), map(), {pos_integer(), pos_integer()},
   pos_integer()}

parser_output()

@type parser_output() ::
  {:ok, list(), binary(), map(), {pos_integer(), pos_integer()}, pos_integer()}

t()

@type t() :: %CaseStyle{from_type: module(), tokens: CaseStyle.Tokens.t()}

Callbacks

matches?(input)

@callback matches?(input :: binary()) :: boolean()

parse(input)

@callback parse(input :: binary()) :: parser_output() | nimble_parsec_error()

to_string(t)

@callback to_string(t()) :: binary()

Functions

camel_to_kebab(input)

@spec camel_to_kebab(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.CamelCase to CaseStyle.KebabCase

camel_to_kebab!(input)

@spec camel_to_kebab!(binary()) :: binary()

same as camel_to_kebab but return a string on success and raises on error on failure

camel_to_pascal(input)

@spec camel_to_pascal(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.CamelCase to CaseStyle.PascalCase

camel_to_pascal!(input)

@spec camel_to_pascal!(binary()) :: binary()

same as camel_to_pascal but return a string on success and raises on error on failure

camel_to_snake(input)

@spec camel_to_snake(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.CamelCase to CaseStyle.SnakeCase

camel_to_snake!(input)

@spec camel_to_snake!(binary()) :: binary()

same as camel_to_snake but return a string on success and raises on error on failure

from_string(input, module)

@spec from_string(binary(), module()) ::
  {:ok, t()} | parser_output() | nimble_parsec_error()

parse given input with the given module

iex> CaseStyle.from_string("snake_case", CaseStyle.SnakeCase)
{:ok,
   %CaseStyle{
     from_type: CaseStyle.SnakeCase,
     tokens: [
       %CaseStyle.Tokens.Start{},
       %CaseStyle.Tokens.FirstLetter{value: ~c"s"},
       %CaseStyle.Tokens.Char{value: ~c"n"},
       %CaseStyle.Tokens.Char{value: ~c"a"},
       %CaseStyle.Tokens.Char{value: ~c"k"},
       %CaseStyle.Tokens.Char{value: ~c"e"},
       %CaseStyle.Tokens.Spacing{},
       %CaseStyle.Tokens.AfterSpacingChar{value: ~c"c"},
       %CaseStyle.Tokens.Char{value: ~c"a"},
       %CaseStyle.Tokens.Char{value: ~c"s"},
       %CaseStyle.Tokens.Char{value: ~c"e"},
       %CaseStyle.Tokens.End{}
     ]
   }
}

graphql_to_snake(input)

@spec graphql_to_snake(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.GraphQLCase to CaseStyle.SnakeCase

graphql_to_snake!(input)

@spec graphql_to_snake!(binary()) :: binary()

same as graphql_to_snake but return a string on success and raises on error on failure

kebab_to_camel(input)

@spec kebab_to_camel(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.KebabCase to CaseStyle.CamelCase

kebab_to_camel!(input)

@spec kebab_to_camel!(binary()) :: binary()

same as kebab_to_camel but return a string on success and raises on error on failure

kebab_to_pascal(input)

@spec kebab_to_pascal(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.KebabCase to CaseStyle.PascalCase

kebab_to_pascal!(input)

@spec kebab_to_pascal!(binary()) :: binary()

same as kebab_to_pascal but return a string on success and raises on error on failure

kebab_to_snake(input)

@spec kebab_to_snake(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.KebabCase to CaseStyle.SnakeCase

kebab_to_snake!(input)

@spec kebab_to_snake!(binary()) :: binary()

same as kebab_to_snake but return a string on success and raises on error on failure

pascal_to_camel(input)

@spec pascal_to_camel(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.PascalCase to CaseStyle.CamelCase

pascal_to_camel!(input)

@spec pascal_to_camel!(binary()) :: binary()

same as pascal_to_camel but return a string on success and raises on error on failure

pascal_to_kebab(input)

@spec pascal_to_kebab(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.PascalCase to CaseStyle.KebabCase

pascal_to_kebab!(input)

@spec pascal_to_kebab!(binary()) :: binary()

same as pascal_to_kebab but return a string on success and raises on error on failure

pascal_to_snake(input)

@spec pascal_to_snake(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.PascalCase to CaseStyle.SnakeCase

pascal_to_snake!(input)

@spec pascal_to_snake!(binary()) :: binary()

same as pascal_to_snake but return a string on success and raises on error on failure

snake_to_camel(input)

@spec snake_to_camel(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.SnakeCase to CaseStyle.CamelCase

snake_to_camel!(input)

@spec snake_to_camel!(binary()) :: binary()

same as snake_to_camel but return a string on success and raises on error on failure

snake_to_graphql(input)

@spec snake_to_graphql(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.SnakeCase to CaseStyle.GraphQLCase

snake_to_graphql!(input)

@spec snake_to_graphql!(binary()) :: binary()

same as snake_to_graphql but return a string on success and raises on error on failure

snake_to_kebab(input)

@spec snake_to_kebab(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.SnakeCase to CaseStyle.KebabCase

snake_to_kebab!(input)

@spec snake_to_kebab!(binary()) :: binary()

same as snake_to_kebab but return a string on success and raises on error on failure

snake_to_pascal(input)

@spec snake_to_pascal(binary()) :: {:ok, binary()} | nimble_parsec_error()

Converts from CaseStyle.SnakeCase to CaseStyle.PascalCase

snake_to_pascal!(input)

@spec snake_to_pascal!(binary()) :: binary()

same as snake_to_pascal but return a string on success and raises on error on failure

to_string(input, module)

@spec to_string(t(), module()) :: binary()

dump given input with the given module

iex> input = %CaseStyle{
...>  from_type: CaseStyle.SnakeCase,
...>  tokens: [
...>   %CaseStyle.Tokens.Start{},
...>   %CaseStyle.Tokens.FirstLetter{value: ~c"s"},
...>   %CaseStyle.Tokens.Char{value: ~c"n"},
...>   %CaseStyle.Tokens.Char{value: ~c"a"},
...>   %CaseStyle.Tokens.Char{value: ~c"k"},
...>   %CaseStyle.Tokens.Char{value: ~c"e"},
...>   %CaseStyle.Tokens.Spacing{},
...>   %CaseStyle.Tokens.AfterSpacingChar{value: ~c"c"},
...>   %CaseStyle.Tokens.Char{value: ~c"a"},
...>   %CaseStyle.Tokens.Char{value: ~c"s"},
...>   %CaseStyle.Tokens.Char{value: ~c"e"},
...>   %CaseStyle.Tokens.End{}
...>  ]
...> }
iex> CaseStyle.to_string(input, CaseStyle.CamelCase)
"snakeCase"