Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new CamelCase function to the sx package that converts strings and string slices to camelCase format. The function follows the existing pattern established by PascalCase but produces camelCase output (first letter lowercase).
- Implements
CamelCasefunction with support for both string and string slice inputs - Adds comprehensive test coverage for various input formats and edge cases
- Introduces a helper function
lowercaseWordfor converting the first character to lowercase
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| sx.go | Adds CamelCase function and lowercaseWord helper function |
| sx_test.go | Comprehensive test cases for both string and slice variants of CamelCase |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| pascalCase := PascalCase(v, opts...) | ||
| return lowercaseWord(pascalCase) |
There was a problem hiding this comment.
Converting to PascalCase first then lowercasing introduces unnecessary work. Consider implementing camelCase directly by reusing the PascalCase logic but applying lowercaseWord to the first word only, similar to how the slice case is handled.
| pascalCase := PascalCase(v, opts...) | |
| return lowercaseWord(pascalCase) | |
| options := CaseConfig{} | |
| for _, opt := range opts { | |
| opt(&options) | |
| } | |
| words := splitByCaseWithCustomSeparators(v, nil) | |
| result := joinWords(words, "", func(word string, i int) string { | |
| normalized := normalizeWord(word, options.Normalize) | |
| if i == 0 { | |
| return lowercaseWord(normalized) | |
| } | |
| return capitalizeWord(normalized) | |
| }) | |
| return result |
📊 Code Coverage ReportCoverage by file |
No description provided.