Kase (kase v1.0.0)

A module for converting strings between different casing styles.

Summary

Types

The target case to convert the string to.

Functions

Compares two strings for equality, ignoring casing differences.

Converts a given string to the specified target_case.

Converts the keys of a given map to the specified target_case.

Types

Link to this type

target_case()

@type target_case() ::
  :camel_case
  | :cobol_case
  | :dot_case
  | :flat_case
  | :humanized_case
  | :kebab_case
  | :pascal_case
  | :snake_case
  | :train_case
  | :upper_case_snake_case

The target case to convert the string to.

Functions

Link to this function

case_invariant_equal?(string1, string2)

Compares two strings for equality, ignoring casing differences.

Examples

iex> Kase.case_invariant_equal?("helloWorld", "hello_world")
true

iex> Kase.case_invariant_equal?("fooBar", "FOO_BAR")
true

iex> Kase.case_invariant_equal?("KaseLib", "case_lib")
false
Link to this function

convert(list, target_case)

@spec convert(String.t() | [String.t()], target_case()) :: String.t()

Converts a given string to the specified target_case.

Examples

iex> Kase.convert("this-variable-name", :camel_case)
"thisVariableName"

iex> Kase.convert(["kool-aid, "royalCrown"], :snake_case)
["kool_aid", "royal_crown"]
Link to this function

convert(map, target_case, options \\ [])

@spec convert(map(), target_case(), Keyword.t()) :: map()

Converts the keys of a given map to the specified target_case.

Examples

map_input = %{"first_key" => "value", "second_key" => "value"}
iex> Kase.convert(map_input, :camel_case)
%{"firstKey" => "value", "secondKey" => "value"}

map_input = %{"first_key" => "value", "second_key" => "value"}
iex> Kase.convert(map_input, :camel_case, to_atoms: true)
%{"firstKey": "value", "secondKey": "value"}