diff --git a/index.js b/index.js index 6d80316..2be1bd1 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/test.js b/test.js index 8c3f82b..4a013f8 100644 --- a/test.js +++ b/test.js @@ -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'); @@ -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');