diff --git a/internal/sdks/sdks.go b/internal/sdks/sdks.go index 289432c0..aed61604 100644 --- a/internal/sdks/sdks.go +++ b/internal/sdks/sdks.go @@ -46,10 +46,10 @@ func ReplaceSDKKeys(instructions string, sdkKey, clientSideId, mobileKey string) return r.Replace(instructions) } -// kebabToCamel converts a kebab-case key string into a camelCase key string, used for the React sdk instructions +// kebabToCamel converts a kebab-case or underscore-separated key string into a camelCase key string, used for the React sdk instructions func kebabToCamel(kebabCase string) string { - replaceDashRegex := regexp.MustCompile(`-(.)`) - camelCase := replaceDashRegex.ReplaceAllStringFunc(kebabCase, func(match string) string { + replaceSeparatorRegex := regexp.MustCompile(`[-_](.)`) + camelCase := replaceSeparatorRegex.ReplaceAllStringFunc(kebabCase, func(match string) string { return strings.ToUpper(string(match[1])) }) return camelCase diff --git a/internal/sdks/sdks_test.go b/internal/sdks/sdks_test.go index 08de2119..29ca8b59 100644 --- a/internal/sdks/sdks_test.go +++ b/internal/sdks/sdks_test.go @@ -34,6 +34,13 @@ func TestReplaceFlagKey(t *testing.T) { assert.Equal(t, string(tt.expected), string(updated)) }) } + + t.Run("replaces camelCase placeholder with underscore key converted to camelCase", func(t *testing.T) { + body := "# title ```const featureFlagKey = \"myFlagKey\"```" + expected := "# title ```const featureFlagKey = \"myCoolFlag\"```" + updated := sdks.ReplaceFlagKey(body, "my_cool_flag") + assert.Equal(t, expected, updated) + }) } func TestReplaceSDKKey(t *testing.T) {