From a95accc0deed1db83803b427c344d611fed9657b Mon Sep 17 00:00:00 2001 From: Richard Zampieri Date: Fri, 15 Nov 2024 00:04:09 -0800 Subject: [PATCH] fix: standardize string utility function formatting and improve readability --- src/generate/utils/string-utils.ts | 38 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/generate/utils/string-utils.ts b/src/generate/utils/string-utils.ts index 1c408d8..3b7532a 100644 --- a/src/generate/utils/string-utils.ts +++ b/src/generate/utils/string-utils.ts @@ -4,9 +4,9 @@ * @returns The converted string in camelCase. */ export function anyCaseToCamelCase(str: string): string { - return str - .replace(/[-_]+(.)?/g, (_, char) => (char ? char.toUpperCase() : '')) - .replace(/^[A-Z]/, (char) => char.toLowerCase()); + return str + .replace(/[-_]+(.)?/g, (_, char) => (char ? char.toUpperCase() : "")) + .replace(/^[A-Z]/, (char) => char.toLowerCase()); } /** @@ -15,10 +15,10 @@ export function anyCaseToCamelCase(str: string): string { * @returns The converted string in kebab-case. */ export function anyCaseToKebabCase(str: string): string { - return str - .replace(/([a-z0-9])([A-Z])/g, '$1-$2') // Convert camelCase and PascalCase to kebab-case - .replace(/_/g, '-') // Convert snake_case to kebab-case - .toLowerCase(); // Ensure all characters are lowercase + return str + .replace(/([a-z0-9])([A-Z])/g, "$1-$2") // Convert camelCase and PascalCase to kebab-case + .replace(/_/g, "-") // Convert snake_case to kebab-case + .toLowerCase(); // Ensure all characters are lowercase } /** @@ -27,9 +27,9 @@ export function anyCaseToKebabCase(str: string): string { * @returns The converted string in PascalCase. */ export function anyCaseToPascalCase(str: string): string { - return str - .replace(/[-_]+(.)?/g, (_, char) => (char ? char.toUpperCase() : '')) - .replace(/^[a-z]/, (char) => char.toUpperCase()); + return str + .replace(/[-_]+(.)?/g, (_, char) => (char ? char.toUpperCase() : "")) + .replace(/^[a-z]/, (char) => char.toUpperCase()); } /** @@ -38,10 +38,10 @@ export function anyCaseToPascalCase(str: string): string { * @returns The converted string in snake_case. */ export function anyCaseToSnakeCase(str: string): string { - return str - .replace(/([a-z0-9])([A-Z])/g, '$1_$2') - .replace(/[-]+/g, '_') - .toLowerCase(); + return str + .replace(/([a-z0-9])([A-Z])/g, "$1_$2") + .replace(/[-]+/g, "_") + .toLowerCase(); } /** @@ -50,7 +50,9 @@ export function anyCaseToSnakeCase(str: string): string { * @returns The converted string in UPPER CASE. */ export function anyCaseToUpperCase(str: string): string { - return str.replace(/[-_]+(.)?/g, (_, char) => (char ? char.toUpperCase() : '')).toUpperCase(); + return str + .replace(/[-_]+(.)?/g, (_, char) => (char ? char.toUpperCase() : "")) + .toUpperCase(); } /** @@ -59,5 +61,7 @@ export function anyCaseToUpperCase(str: string): string { * @returns The converted string in lower case. */ export function anyCaseToLowerCase(str: string): string { - return str.replace(/[-_]+(.)?/g, (_, char) => (char ? char.toLowerCase() : '')).toLowerCase(); -} \ No newline at end of file + return str + .replace(/[-_]+(.)?/g, (_, char) => (char ? char.toLowerCase() : "")) + .toLowerCase(); +}