param str export function capitalize ( str ) { return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ; } param str export function hasSymbols ( str ) { return /[!"#%&'()*+,./:;<=>?@[\\\]^`{|}]/u . exec ( str ) ; } param str export function hasUpper ( str ) { return /[A-Z]/u . exec ( str ) ; } param str export function kebabCase ( str ) { return str . replace ( /_/gu , '-' ) . replace ( /\B([A-Z])/gu , '-$1' ) . toLowerCase ( ) ; } param str export function isKebabCase ( str ) { if ( hasUpper ( str ) || hasSymbols ( str ) || /^-/u . exec ( str ) || /_|--|\s/u . exec ( str ) ) { return false ; } return true ; } param str export function snakeCase ( str ) { return str . replace ( /\B([A-Z])/gu , '_$1' ) . replace ( /-/gu , '_' ) . toLowerCase ( ) ; } param str export function isSnakeCase ( str ) { if ( hasUpper ( str ) || hasSymbols ( str ) || /-|__|\s/u . exec ( str ) ) { return false ; } return true ; } param str export function camelCase ( str ) { if ( isPascalCase ( str ) ) { return str . charAt ( 0 ) . toLowerCase ( ) + str . slice ( 1 ) ; } return str . replace ( /[-_](\w)/gu , ( _ , c ) => ( c ? c . toUpperCase ( ) : '' ) ) ; } param str export function isCamelCase ( str ) { if ( hasSymbols ( str ) || /^[A-Z]/u . exec ( str ) || /-|_|\s/u . exec ( str ) ) { return false ; } return true ; } param str return export function pascalCase ( str ) { return capitalize ( camelCase ( str ) ) ; } param str export function isPascalCase ( str ) { if ( hasSymbols ( str ) || /^[a-z]/u . exec ( str ) || /-|_|\s/u . exec ( str ) ) { return false ; } return true ; } export type CaseType = 'camelCase' | 'kebab-case' | 'PascalCase' | 'snake_case' ; export const checkersMap = { 'kebab-case' : isKebabCase , snake_case : isSnakeCase , camelCase : isCamelCase , PascalCase : isPascalCase } ; param name return export function getChecker ( name ) { return checkersMap [ name ] || isPascalCase ; } export const convertersMap = { 'kebab-case' : kebabCase , snake_case : snakeCase , camelCase , PascalCase : pascalCase } ; param name return export function getConverter ( name ) { return convertersMap [ name ] || pascalCase ; } export const allowedCaseOptions = [ 'camelCase' , 'kebab-case' , 'PascalCase' ] ; param name return export function getExactConverter ( name ) { const converter = getConverter ( name ) ; const checker = getChecker ( name ) ; return ( str ) => { const result = converter ( str ) ; return checker ( result ) ? result : str ; } ; }