feat: enhance name formatting functions to include PascalCase conversion

This commit is contained in:
2026-03-27 14:09:30 +01:00
parent ddca01e4e9
commit 603feda26d
2 changed files with 23 additions and 4 deletions

View File

@@ -1,12 +1,31 @@
/**
* Converts a PascalCase name to camelCase by lowercasing the first character.
* Converts a string to PascalCase, handling spaces, hyphens and underscores.
* Used to derive class names from schema/tag names.
*
* @example
* toPascalCase('Product Format') // 'ProductFormat'
* toPascalCase('user-response') // 'UserResponse'
* toPascalCase('UserSchema') // 'UserSchema'
*/
export function toPascalCase(name: string): string {
if (!name) return name;
return name
.split(/[\s\-_]+/)
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join('');
}
/**
* Converts a string to camelCase, handling spaces, hyphens and underscores.
* Used to derive class filenames and variable names from schema/tag names.
*
* @example
* toCamelCase('Product Format') // 'productFormat'
* toCamelCase('ProductResponse') // 'productResponse'
* toCamelCase('UserSchema') // 'userSchema'
*/
export function toCamelCase(name: string): string {
if (!name) return name;
return name.charAt(0).toLowerCase() + name.slice(1);
const pascal = toPascalCase(name);
return pascal.charAt(0).toLowerCase() + pascal.slice(1);
}