const fromCamel = ( str ) => { const parts = str . replace ( /([A-Z])/g , '_$1' ) . toLowerCase ( ) . split ( '_' ) ; return fromParts ( parts ) ; } ; const fromSplit = ( split ) => ( str ) => { const parts = str . split ( split ) ; return fromParts ( parts ) ; } ; const fromSnake = fromSplit ( '_' ) ; const fromKebab = fromSplit ( '-' ) ; const fromParts = ( parts ) => ( { toCamel : ( ) => toCamel ( parts ) , toKebab : ( ) => toKebab ( parts ) , toSnake : ( ) => toSnake ( parts ) , } ) ; const toJoin = ( join ) => ( parts ) => parts . join ( join ) ; const toSnake = toJoin ( '_' ) ; const toKebab = toJoin ( '-' ) ; const toCamel = ( parts ) => { const [ first , ... rest ] = parts ; return [ first , ... rest . map ( ( str ) => `${ str [ 0 ] . toUpperCase ( ) }${ str . slice ( 1 ) }` ) ] . join ( '' ) ; } ; const detectCase = ( str ) => { if ( /_/ . test ( str ) ) return 'snake' ; if ( /-/ . test ( str ) ) return 'kebab' ; if ( /[A-Z]/ . test ( str ) ) return 'camel' ; } ; const fromAny = ( str ) => { switch ( detectCase ( str ) ) { case 'snake' : return fromSnake ( str ) ; case 'camel' : return fromCamel ( str ) ; case 'kebab' : return fromKebab ( str ) ; } } ; export const fromCamelToSnake = ( str ) => fromCamel ( str ) . toSnake ( ) ; export const fromCamelToKebab = ( str ) => fromCamel ( str ) . toKebab ( ) ; export const fromSnakeToCamel = ( str ) => fromSnake ( str ) . toCamel ( ) ; export const fromSnakeToKebab = ( str ) => fromSnake ( str ) . toKebab ( ) ; export const fromKebabToCamel = ( str ) => fromKebab ( str ) . toCamel ( ) ; export const fromKebabToSnake = ( str ) => fromKebab ( str ) . toSnake ( ) ; export const fromAnyToCamel = ( str ) => fromAny ( str ) . toCamel ( ) ; export const fromAnyToSnake = ( str ) => fromAny ( str ) . toSnake ( ) ; export const fromAnyToKebab = ( str ) => fromAny ( str ) . toKebab ( ) ;