const returnOrThrow = ( convertedString , originalString , stringCase ) : string => { if ( typeof convertedString === 'string' && convertedString !== '' ) { return convertedString ; } throw new Error ( `converting "${ originalString }" to ${ stringCase }, resulting in "${ convertedString }"` ) ; } ; const toCamelCase = ( string ) : string => { const convertedString = string . toLowerCase ( ) . replace ( /['"]/g , '' ) . replace ( /([-_ ]){1,}/g , ' ' ) . replace ( /\W+/g , ' ' ) . trim ( ) . replace ( / (.)/g , function ( $1 ) { return $1 . toUpperCase ( ) ; } ) . replace ( / /g , '' ) ; return returnOrThrow ( convertedString , string , 'camelCase' ) ; } ; const toKebabCase = ( string ) : string => { const convertedString = string . toLowerCase ( ) . replace ( /['"]/g , '' ) . replace ( /([-_ ]){1,}/g , ' ' ) . replace ( /\W+/g , ' ' ) . trim ( ) . replace ( / /g , '-' ) ; return returnOrThrow ( convertedString , string , 'kebabCase' ) ; } ; const transformName = ( name , nameConversion = 'default' ) : string => { if ( nameConversion === 'camelCase' ) { return toCamelCase ( name ) ; } if ( nameConversion === 'kebabCase' ) { return toKebabCase ( name ) ; } return name . trim ( ) . toLowerCase ( ) ; } ; export default transformName ; export const __testing = { toCamelCase : toCamelCase , toKebabCase : toKebabCase } ;