Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/sdks/sdks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions internal/sdks/sdks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading