camelcase
Advanced tools
Comparing version 7.0.0 to 7.0.1
@@ -11,9 +11,11 @@ const UPPERCASE = /[\p{Lu}]/u; | ||
const preserveCamelCase = (string, toLowerCase, toUpperCase) => { | ||
const preserveCamelCase = (string, toLowerCase, toUpperCase, preserveConsecutiveUppercase) => { | ||
let isLastCharLower = false; | ||
let isLastCharUpper = false; | ||
let isLastLastCharUpper = false; | ||
let isLastLastCharPreserved = false; | ||
for (let index = 0; index < string.length; index++) { | ||
const character = string[index]; | ||
isLastLastCharPreserved = index > 2 ? string[index - 3] === '-' : true; | ||
@@ -26,3 +28,3 @@ if (isLastCharLower && UPPERCASE.test(character)) { | ||
index++; | ||
} else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character)) { | ||
} else if (isLastCharUpper && isLastLastCharUpper && LOWERCASE.test(character) && (!isLastLastCharPreserved || preserveConsecutiveUppercase)) { | ||
string = string.slice(0, index - 1) + '-' + string.slice(index - 1); | ||
@@ -98,3 +100,3 @@ isLastLastCharUpper = isLastCharUpper; | ||
if (hasUpperCase) { | ||
input = preserveCamelCase(input, toLowerCase, toUpperCase); | ||
input = preserveCamelCase(input, toLowerCase, toUpperCase, options.preserveConsecutiveUppercase); | ||
} | ||
@@ -101,0 +103,0 @@ |
{ | ||
"name": "camelcase", | ||
"version": "7.0.0", | ||
"version": "7.0.1", | ||
"description": "Convert a dash/dot/underscore/space separated string to camelCase or PascalCase: `foo-bar` → `fooBar`", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
11720
160