Skip to content

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

Merged
sindresorhus merged 4 commits into
sindresorhus:mainfrom
JCrandall101:main
Aug 9, 2023
Merged

Removing casing to characters after a number that are followed by a separator (issue #77)#112
sindresorhus merged 4 commits into
sindresorhus:mainfrom
JCrandall101:main

Conversation

@JCrandall101
Copy link
Copy Markdown
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
Comment thread index.js Outdated

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
Copy Markdown
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
Copy Markdown
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

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