From 6c38452338ec0e69464b7bedf66434d5c13250ea Mon Sep 17 00:00:00 2001 From: Cail Borg Date: Tue, 31 Oct 2023 10:46:53 +1100 Subject: [PATCH 1/2] update toCamelCase to check for existing case before applying a conversion --- src/utilities/transformName.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/utilities/transformName.ts b/src/utilities/transformName.ts index cb4a0695..b7e84b0f 100644 --- a/src/utilities/transformName.ts +++ b/src/utilities/transformName.ts @@ -8,6 +8,12 @@ const returnOrThrow = (convertedString: string, originalString: string, stringCa } const toCamelCase = (string: string): string => { + // check if the string is already in camel case + if (/^[a-z]+([A-Z][a-z]*)*$/.test(string)) { + // return the string as it is + return string; + } + // otherwise, apply the conversion logic const convertedString: string = string.toLowerCase() .replace(/['"]/g, '') .replace(/([-_ ]){1,}/g, ' ') From ac7ea4ff118db1bd48d7064ee01819b9c237911f Mon Sep 17 00:00:00 2001 From: Cail Borg Date: Fri, 3 Nov 2023 11:43:46 +1100 Subject: [PATCH 2/2] updated code to work with numbers --- src/utilities/transformName.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utilities/transformName.ts b/src/utilities/transformName.ts index b7e84b0f..a18d8441 100644 --- a/src/utilities/transformName.ts +++ b/src/utilities/transformName.ts @@ -14,7 +14,7 @@ const toCamelCase = (string: string): string => { return string; } // otherwise, apply the conversion logic - const convertedString: string = string.toLowerCase() + const convertedString: string = string.charAt(0).toLowerCase() + string.slice(1) .replace(/['"]/g, '') .replace(/([-_ ]){1,}/g, ' ') .replace(/\W+/g, ' ') @@ -25,6 +25,7 @@ const toCamelCase = (string: string): string => { return returnOrThrow(convertedString, string, 'camelCase') } + const toKebabCase = (string: string): string => { const convertedString: string = string.toLowerCase() .replace(/['"]/g, '')