Skip to content

Commit e7dccc9

Browse files
authored
Fix incorrect camelization (#112)
1 parent c9fa59d commit e7dccc9

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ const postProcess = (input, toUpperCase) => {
4949
SEPARATORS_AND_IDENTIFIER.lastIndex = 0;
5050
NUMBERS_AND_IDENTIFIER.lastIndex = 0;
5151

52-
return input.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier))
53-
.replace(NUMBERS_AND_IDENTIFIER, m => toUpperCase(m));
52+
return input.replace(NUMBERS_AND_IDENTIFIER, (match, pattern, offset) => ['_', '-'].includes(input.charAt(offset + match.length)) ? match : toUpperCase(match))
53+
.replace(SEPARATORS_AND_IDENTIFIER, (_, identifier) => toUpperCase(identifier));
5454
};
5555

5656
export default function camelCase(input, options) {

test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import test from 'ava';
22
import camelCase from './index.js';
33

44
test('camelCase', t => {
5+
t.is(camelCase('b2b_registration_request'), 'b2bRegistrationRequest');
6+
t.is(camelCase('b2b-registration-request'), 'b2bRegistrationRequest');
7+
t.is(camelCase('b2b_registration_b2b_request'), 'b2bRegistrationB2bRequest');
58
t.is(camelCase('foo'), 'foo');
69
t.is(camelCase('IDs'), 'ids');
710
t.is(camelCase('FooIDs'), 'fooIds');
@@ -76,6 +79,7 @@ test('camelCase', t => {
7679
});
7780

7881
test('camelCase with pascalCase option', t => {
82+
t.is(camelCase('b2b_registration_request', {pascalCase: true}), 'B2bRegistrationRequest');
7983
t.is(camelCase('foo', {pascalCase: true}), 'Foo');
8084
t.is(camelCase('foo-bar', {pascalCase: true}), 'FooBar');
8185
t.is(camelCase('foo-bar-baz', {pascalCase: true}), 'FooBarBaz');

0 commit comments

Comments
 (0)