11/**
22 * Case transformation utilities
3+ *
4+ * Pure case transforms are delegated to komoji (the origin of truth).
5+ * This module re-exports them for backward compatibility and adds
6+ * inflekt-specific helpers (fixCapitalisedPlural, underscore, toScreamingSnake).
37 */
48
5- /**
6- * Convert PascalCase to camelCase (lowercase first character)
7- * @example "UserProfile" -> "userProfile"
8- */
9- export function lcFirst ( str : string ) : string {
10- return str . charAt ( 0 ) . toLowerCase ( ) + str . slice ( 1 ) ;
11- }
9+ import {
10+ lcFirst ,
11+ ucFirst ,
12+ toCamelCase as _toCamelCase ,
13+ toPascalCase ,
14+ toSnakeCase ,
15+ toConstantCase ,
16+ } from 'komoji' ;
1217
13- /**
14- * Convert camelCase to PascalCase (uppercase first character)
15- * @example "userProfile" -> "UserProfile"
16- */
17- export function ucFirst ( str : string ) : string {
18- return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
18+ // Re-export komoji functions directly
19+ export { lcFirst , ucFirst , toPascalCase , toSnakeCase , toConstantCase } ;
20+
21+ // Re-export toCamelCase — komoji's version accepts a second parameter
22+ // (stripLeadingNonAlphabetChars) so we wrap to keep the simpler inflekt signature
23+ export function toCamelCase ( str : string ) : string {
24+ return _toCamelCase ( str ) ;
1925}
2026
2127/**
@@ -29,51 +35,20 @@ export function fixCapitalisedPlural(str: string): string {
2935
3036/**
3137 * Convert PascalCase or camelCase to snake_case
38+ * @deprecated Use toSnakeCase from komoji instead
3239 * @example underscore('UserProfile') -> 'user_profile'
3340 * @example underscore('userProfile') -> 'user_profile'
3441 */
3542export function underscore ( str : string ) : string {
36- return str
37- . replace ( / ( [ A - Z ] ) / g, '_$1' )
38- . replace ( / ^ _ / , '' )
39- . toLowerCase ( ) ;
40- }
41-
42- /**
43- * Convert a hyphenated, underscored, or already-camelCased string to camelCase.
44- * Handles both `-` and `_` delimiters.
45- * @example toCamelCase('user-profile') -> 'userProfile'
46- * @example toCamelCase('user_profile') -> 'userProfile'
47- * @example toCamelCase('UserProfile') -> 'userProfile'
48- */
49- export function toCamelCase ( str : string ) : string {
50- return str
51- . replace ( / [ - _ ] ( .) / g, ( _ , char ) => char . toUpperCase ( ) )
52- . replace ( / ^ ( .) / , ( _ , char ) => char . toLowerCase ( ) ) ;
53- }
54-
55- /**
56- * Convert a hyphenated, underscored, or already-camelCased string to PascalCase.
57- * Handles both `-` and `_` delimiters.
58- * @example toPascalCase('user-profile') -> 'UserProfile'
59- * @example toPascalCase('user_profile') -> 'UserProfile'
60- * @example toPascalCase('userProfile') -> 'UserProfile'
61- */
62- export function toPascalCase ( str : string ) : string {
63- return str
64- . replace ( / [ - _ ] ( .) / g, ( _ , char ) => char . toUpperCase ( ) )
65- . replace ( / ^ ( .) / , ( _ , char ) => char . toUpperCase ( ) ) ;
43+ return toSnakeCase ( str ) ;
6644}
6745
6846/**
6947 * Convert a camelCase or PascalCase string to SCREAMING_SNAKE_CASE.
48+ * @deprecated Use toConstantCase from komoji instead
7049 * @example toScreamingSnake('userProfile') -> 'USER_PROFILE'
7150 * @example toScreamingSnake('UserProfile') -> 'USER_PROFILE'
7251 */
7352export function toScreamingSnake ( str : string ) : string {
74- return str
75- . replace ( / ( [ A - Z ] ) / g, '_$1' )
76- . replace ( / [ - \s ] / g, '_' )
77- . toUpperCase ( )
78- . replace ( / ^ _ / , '' ) ;
53+ return toConstantCase ( str ) ;
7954}
0 commit comments