add test cases for toCamelCase for forceCapitalization param
* add test cases for toCamelCase for forceCapitalization
add a ternary to handle all cap characters
* update a snapshot for jsxPascalCase rule that uses toCamelCase
MODIFY
packages/@romejs/string-utils/toCamelCase.test.ts
packages/@romejs/string-utils/toCamelCase.test.ts
@@ -11,15 +11,22 @@ import {test} from "rome";
test(
"toCamelCase",
(t) => {
- const testCases = [
+ [
{input: "rometest", expected: "rometest"},
{input: "rome test", expected: "romeTest"},
{input: "RoMe TeSt", expected: "RoMeTeSt"},
- {input: "ROME TEST", expected: "ROMETEST"},
- ];
-
- testCases.forEach((td) => {
+ {input: "ROME TEST", expected: "RomeTest"},
+ ].forEach((td) => {
t.is(toCamelCase(td.input), td.expected);
});
+
+ [
+ {input: "rometest", expected: "Rometest"},
+ {input: "rome test", expected: "RomeTest"},
+ {input: "RoMe TeSt", expected: "RoMeTeSt"},
+ {input: "ROME TEST", expected: "RomeTest"},
+ ].forEach((td) => {
+ t.is(toCamelCase(td.input, true), td.expected);
+ });
},
);

MODIFY
packages/@romejs/string-utils/toCamelCase.ts
packages/@romejs/string-utils/toCamelCase.ts
@@ -11,8 +11,8 @@ export function toCamelCase(str: string, forceCapitalize?: boolean): string {
return str;
}
- // Prepend uppercase letters with a space
- str = str.replace(/([A-Z+])/g, " $1");
+ // Prepend uppercase letters with a space unless all characters are uppercase
+ str = str.toUpperCase() === str ? ` ${str}` : str.replace(/([A-Z+])/g, " $1");
// We no longer care about the casing
str = str.toLowerCase();

add test cases for toCamelCase for forceCapitalization param (#555)

* add test cases for toCamelCase for forceCapitalization
add a ternary to handle all cap characters

* update a snapshot for jsxPascalCase rule that uses toCamelCase