Skip to content

fix: do not capitalize letter after digit in camelCase conversion - #57

Open
Yanhu007 wants to merge 1 commit into
iancoleman:masterfrom
Yanhu007:fix/digit-to-letter-capitalization
Open

fix: do not capitalize letter after digit in camelCase conversion#57
Yanhu007 wants to merge 1 commit into
iancoleman:masterfrom
Yanhu007:fix/digit-to-letter-capitalization

Conversation

@Yanhu007

Copy link
Copy Markdown

Fixes #51

Problem

ToLowerCamel and ToCamel incorrectly capitalize the letter immediately following a digit sequence:

Input Got Expected
k8s_version k8SVersion k8sVersion
i18n_key i18NKey i18nKey
l10n_us l10NUs l10nUs

This is because every digit sets capNext = true, treating digit-to-letter transitions as word boundaries.

Fix

Remove capNext = true after digits. Only explicit delimiters (_, , -, .) should trigger word boundaries and capitalization. Alphanumeric identifiers like k8s, i18n, l10n are single words and should not be split at the digit-letter boundary.

The test case for numbers2And55with000 was updated to reflect the corrected behavior (55with stays lowercase).

All existing tests pass.

Previously, every digit-to-letter transition was treated as a word
boundary, causing the letter after digits to be capitalized:

  k8s_version → k8SVersion (wrong, expected k8sVersion)
  i18n_key → i18NKey (wrong, expected i18nKey)
  l10n_us → l10NUs (wrong, expected l10nUs)

The digit-to-letter transition is not a word boundary in common
identifiers like k8s, i18n, l10n. Only explicit delimiters
(underscore, space, hyphen, dot) should trigger capitalization.

Updated the test expectation for numbers2And55with000 to match
the corrected behavior (55with stays lowercase, not 55With).

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