@@ -8,21 +8,23 @@ const LEADING_SEPARATORS = new RegExp('^' + SEPARATORS.source);
8
8
const SEPARATORS_AND_IDENTIFIER = new RegExp ( SEPARATORS . source + IDENTIFIER . source , 'gu' ) ;
9
9
const NUMBERS_AND_IDENTIFIER = new RegExp ( '\\d+' + IDENTIFIER . source , 'gu' ) ;
10
10
11
- const preserveCamelCase = ( string , toLowerCase , toUpperCase ) => {
11
+ const preserveCamelCase = ( string , toLowerCase , toUpperCase , preserveConsecutiveUppercase ) => {
12
12
let isLastCharLower = false ;
13
13
let isLastCharUpper = false ;
14
14
let isLastLastCharUpper = false ;
15
+ let isLastLastCharPreserved = false ;
15
16
16
17
for ( let index = 0 ; index < string . length ; index ++ ) {
17
18
const character = string [ index ] ;
19
+ isLastLastCharPreserved = index > 2 ? string [ index - 3 ] === '-' : true ;
18
20
19
21
if ( isLastCharLower && UPPERCASE . test ( character ) ) {
20
22
string = string . slice ( 0 , index ) + '-' + string . slice ( index ) ;
21
23
isLastCharLower = false ;
22
24
isLastLastCharUpper = isLastCharUpper ;
23
25
isLastCharUpper = true ;
24
26
index ++ ;
25
- } else if ( isLastCharUpper && isLastLastCharUpper && LOWERCASE . test ( character ) ) {
27
+ } else if ( isLastCharUpper && isLastLastCharUpper && LOWERCASE . test ( character ) && ( ! isLastLastCharPreserved || preserveConsecutiveUppercase ) ) {
26
28
string = string . slice ( 0 , index - 1 ) + '-' + string . slice ( index - 1 ) ;
27
29
isLastLastCharUpper = isLastCharUpper ;
28
30
isLastCharUpper = false ;
@@ -93,7 +95,7 @@ export default function camelCase(input, options) {
93
95
const hasUpperCase = input !== toLowerCase ( input ) ;
94
96
95
97
if ( hasUpperCase ) {
96
- input = preserveCamelCase ( input , toLowerCase , toUpperCase ) ;
98
+ input = preserveCamelCase ( input , toLowerCase , toUpperCase , options . preserveConsecutiveUppercase ) ;
97
99
}
98
100
99
101
input = input . replace ( LEADING_SEPARATORS , '' ) ;
0 commit comments