Skip to content

Commit 3b5cd90

Browse files
rodriguesmattpolzin
authored andcommitted
fix regression when first word is pascal casing
1 parent ae78a7d commit 3b5cd90

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/jsonapi/utils/string.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ defmodule JSONAPI.Utils.String do
115115
iex> camelize("alreadyCamelized_id")
116116
"alreadyCamelizedId"
117117
118+
iex> camelize("PascalLambda_id")
119+
"pascalLambdaId"
120+
118121
"""
119122
@spec camelize(atom) :: String.t()
120123
def camelize(value) when is_atom(value) do
@@ -138,7 +141,9 @@ defmodule JSONAPI.Utils.String do
138141

139142
# If there are multiple words, perform the camelizing
140143
[h | t] ->
141-
Enum.join([h | camelize_list(t)])
144+
{first_character, rest_word} = String.split_at(h, 1)
145+
first_word = String.downcase(first_character) <> rest_word
146+
Enum.join([first_word | camelize_list(t)])
142147
end
143148
end
144149

0 commit comments

Comments
 (0)