Skip to content

Commit

Permalink
Fix incorrect camelization (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
JCrandall101 committed Aug 9, 2023
1 parent c9fa59d commit e7dccc9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -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, (match, pattern, offset) => ['_', '-'].includes(input.charAt(offset + match.length)) ? match : toUpperCase(match))
.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier));
};

export default function camelCase(input, options) {
Expand Down
4 changes: 4 additions & 0 deletions test.js
Expand Up @@ -2,6 +2,9 @@ import test from 'ava';
import camelCase from './index.js';

test('camelCase', t => {
t.is(camelCase('b2b_registration_request'), 'b2bRegistrationRequest');
t.is(camelCase('b2b-registration-request'), 'b2bRegistrationRequest');
t.is(camelCase('b2b_registration_b2b_request'), 'b2bRegistrationB2bRequest');
t.is(camelCase('foo'), 'foo');
t.is(camelCase('IDs'), 'ids');
t.is(camelCase('FooIDs'), 'fooIds');
Expand Down Expand Up @@ -76,6 +79,7 @@ test('camelCase', t => {
});

test('camelCase with pascalCase option', t => {
t.is(camelCase('b2b_registration_request', {pascalCase: true}), 'B2bRegistrationRequest');
t.is(camelCase('foo', {pascalCase: true}), 'Foo');
t.is(camelCase('foo-bar', {pascalCase: true}), 'FooBar');
t.is(camelCase('foo-bar-baz', {pascalCase: true}), 'FooBarBaz');
Expand Down

0 comments on commit e7dccc9

Please sign in to comment.