Skip to content

Commit

Permalink
fix regression when first word is pascal casing
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigues authored and mattpolzin committed Nov 2, 2024
1 parent ae78a7d commit 3b5cd90
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/jsonapi/utils/string.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ defmodule JSONAPI.Utils.String do
iex> camelize("alreadyCamelized_id")
"alreadyCamelizedId"
iex> camelize("PascalLambda_id")
"pascalLambdaId"
"""
@spec camelize(atom) :: String.t()
def camelize(value) when is_atom(value) do
Expand All @@ -138,7 +141,9 @@ defmodule JSONAPI.Utils.String do

# If there are multiple words, perform the camelizing
[h | t] ->
Enum.join([h | camelize_list(t)])
{first_character, rest_word} = String.split_at(h, 1)
first_word = String.downcase(first_character) <> rest_word
Enum.join([first_word | camelize_list(t)])
end
end

Expand Down

0 comments on commit 3b5cd90

Please sign in to comment.