Skip to content

fix: do not treat digits as word boundaries in camelCase conversion - #58

Open
Yanhu007 wants to merge 1 commit into
iancoleman:masterfrom
Yanhu007:fix/digit-not-word-boundary
Open

fix: do not treat digits as word boundaries in camelCase conversion#58
Yanhu007 wants to merge 1 commit into
iancoleman:masterfrom
Yanhu007:fix/digit-not-word-boundary

Conversation

@Yanhu007

Copy link
Copy Markdown

Fixes #51

Problem

Digits set capNext = true, causing the first letter after a digit to be capitalized:

strcase.ToLowerCamel("k8s_version") // → "k8SVersion" (wrong)
strcase.ToLowerCamel("l10n_us")     // → "l10NUs"     (wrong)
strcase.ToCamel("my2ndItem")        // → "My2NdItem"  (wrong)

Fix

Remove the capNext = true for digits. Only explicit delimiters (_, , -, .) create word boundaries:

strcase.ToLowerCamel("k8s_version") // → "k8sVersion" ✓
strcase.ToLowerCamel("l10n_us")     // → "l10nUs"     ✓
strcase.ToCamel("my2ndItem")        // → "My2ndItem"  ✓
strcase.ToLowerCamel("some_v2_api") // → "someV2Api"  ✓ (underscore still works)

One test expectation updated to reflect the new behavior.
All existing tests pass.

Digits were setting capNext=true, causing the first letter after
a digit sequence to be capitalized. This produced incorrect results
for common patterns like k8s, l10n, v2:

  ToLowerCamel("k8s_version") → "k8SVersion" (wrong)
  ToLowerCamel("l10n_us")     → "l10NUs"     (wrong)

Now digits do not trigger capitalization — only explicit delimiters
(underscore, space, dash, dot) create word boundaries:

  ToLowerCamel("k8s_version") → "k8sVersion" (correct)
  ToLowerCamel("l10n_us")     → "l10nUs"     (correct)

Fixes iancoleman#51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ToLowerCamel producing incorrect value for some snake case strings

1 participant