From 8c480c504c116dfa9ff00abf854bff6a1a52a972 Mon Sep 17 00:00:00 2001 From: Victor Rodrigues Date: Fri, 1 Nov 2024 12:00:17 +0100 Subject: [PATCH] fix regression when first word is pascal casing --- lib/jsonapi/utils/string.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/jsonapi/utils/string.ex b/lib/jsonapi/utils/string.ex index a8d36b6e..206f730e 100644 --- a/lib/jsonapi/utils/string.ex +++ b/lib/jsonapi/utils/string.ex @@ -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 @@ -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