diff --git a/packages/inflekt/__tests__/inflection.test.ts b/packages/inflekt/__tests__/inflection.test.ts index 6d86a36..862f603 100644 --- a/packages/inflekt/__tests__/inflection.test.ts +++ b/packages/inflekt/__tests__/inflection.test.ts @@ -141,6 +141,18 @@ describe('camelize', () => { expect(camelize('api_schema', true)).toBe('apiSchema'); }); + it('should convert kebab-case to PascalCase by default', () => { + expect(camelize('schema-file')).toBe('SchemaFile'); + expect(camelize('dry-run')).toBe('DryRun'); + expect(camelize('output-dir')).toBe('OutputDir'); + }); + + it('should convert kebab-case to camelCase when lowFirstLetter is true', () => { + expect(camelize('schema-file', true)).toBe('schemaFile'); + expect(camelize('dry-run', true)).toBe('dryRun'); + expect(camelize('output-dir', true)).toBe('outputDir'); + }); + it('should handle single words', () => { expect(camelize('user')).toBe('User'); expect(camelize('user', true)).toBe('user'); diff --git a/packages/inflekt/src/case.ts b/packages/inflekt/src/case.ts index 9bc7c13..7be701b 100644 --- a/packages/inflekt/src/case.ts +++ b/packages/inflekt/src/case.ts @@ -28,15 +28,17 @@ export function fixCapitalisedPlural(str: string): string { } /** - * Convert snake_case to PascalCase (or camelCase if lowFirstLetter is true) - * @param str - The snake_case string to convert + * Convert snake_case or kebab-case to PascalCase (or camelCase if lowFirstLetter is true) + * @param str - The snake_case or kebab-case string to convert * @param lowFirstLetter - If true, returns camelCase instead of PascalCase * @example camelize('user_profile') -> 'UserProfile' * @example camelize('user_profile', true) -> 'userProfile' + * @example camelize('schema-file') -> 'SchemaFile' + * @example camelize('schema-file', true) -> 'schemaFile' */ export function camelize(str: string, lowFirstLetter?: boolean): string { const result = str - .split('_') + .split(/[-_]/) .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) .join('');