Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing casing to characters after a number that are followed by a separator (issue #77) #112

Merged
merged 4 commits into from
Aug 9, 2023

Conversation

JCrandall101
Copy link
Contributor

@JCrandall101 JCrandall101 commented Jul 24, 2023

In this PR

Based on issue #77 for the following comment

The following example the returns the expected:
Expected: b2b_registration_request -> b2bRegistrationRequest
Received: b2b_registration_request -> b2BRegistrationRequest

Assumptions:

  • If a letter proceeded by a number is followed by an underscore or dash, the letter should not be upper cased

index.js

  • Reordered the replace functions to be able to check for separators
  • Added ternary function to check if the character after the replace value is a underscore or dash and only changing case if it is not

test.js

  • Added 4 tests for the example string

Fixes #77

@JCrandall101 JCrandall101 changed the title Removing casing to characters after a number that are followed by a separator Removing casing to characters after a number that are followed by a separator (issue 77) Jul 24, 2023
@JCrandall101 JCrandall101 changed the title Removing casing to characters after a number that are followed by a separator (issue 77) Removing casing to characters after a number that are followed by a separator (issue #77) Jul 24, 2023
index.js Outdated
@@ -49,8 +49,8 @@ const postProcess = (input, toUpperCase) => {
SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
NUMBERS_AND_IDENTIFIER.lastIndex = 0;

return input.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier))
.replace(NUMBERS_AND_IDENTIFIER, m => toUpperCase(m));
return input.replace(NUMBERS_AND_IDENTIFIER, (m, n, i) => ['_', '-'].includes(input.charAt(i + m.length)) ? m : toUpperCase(m))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use one character variable names.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, updated variables

@sindresorhus sindresorhus merged commit e7dccc9 into sindresorhus:main Aug 9, 2023
3 checks passed
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.

Converting either volume_3d or volume3d results in volume3D making it impossible to decamelize
2 participants