TailwindVariants.Utils (tailwind_variants v0.1.0)
View SourceUtility functions for manipulating class names.
Summary
Functions
Convert a map to atom keys. Warning that this is not a recursive function and is unsafe and could result in a denial of service attack if you exceed the atom limit.
Joins class names, handling nil, empty strings, and nested arrays.
Merges class names using tw_merge if enabled in config.
Recursively converts all keys in a map to strings. Handles nested maps and lists of maps.
Convert a string to an atom.
Functions
Convert a map to atom keys. Warning that this is not a recursive function and is unsafe and could result in a denial of service attack if you exceed the atom limit.
Examples
iex> atomize_keys(%{"name" => "John", "age" => 30})
%{name: "John", age: 30}
iex> atomize_keys(%{"user" => %{"name" => "John", "age" => 30}})
%{user: %{name: "John", age: 30}}
Joins class names, handling nil, empty strings, and nested arrays.
Examples
iex> join_class_names(["font-bold", "text-lg"])
"font-bold text-lg"
iex> join_class_names(["font-bold", nil, "text-lg"])
"font-bold text-lg"
iex> join_class_names(["font-bold", ["text-lg", "p-4"]])
"font-bold text-lg p-4"
Merges class names using tw_merge if enabled in config.
Examples
iex> merge_class_names(["p-4", "p-6"], %{tw_merge: true})
"p-6"
iex> merge_class_names(["p-4", "p-6"], %{tw_merge: false})
"p-4 p-6"
Recursively converts all keys in a map to strings. Handles nested maps and lists of maps.
Examples
iex> stringify_keys(%{name: "John", age: 30})
%{"name" => "John", "age" => 30}
iex> stringify_keys(%{user: %{name: "John", age: 30}})
%{"user" => %{"name" => "John", "age" => 30}}
Convert a string to an atom.