export function isUppercase ( char = '' ) { return char . toUpperCase ( ) === char ; } const STR_SPLITTERS = [ '-' , '_' , '/' , '.' ] ; export function splitByCase ( str , splitters = STR_SPLITTERS ) { const parts = [ ] ; if ( ! str || typeof str !== 'string' ) { return parts ; } let buff = '' ; let previusUpper = null ; let previousSplitter = null ; for ( const char of str . split ( '' ) ) { const isSplitter = splitters . includes ( char ) ; if ( isSplitter === true ) { parts . push ( buff ) ; buff = '' ; previusUpper = null ; continue ; } const isUpper = isUppercase ( char ) ; if ( previousSplitter === false ) { if ( previusUpper === false && isUpper === true ) { parts . push ( buff ) ; buff = char ; previusUpper = isUpper ; continue ; } if ( previusUpper === true && isUpper === false && buff . length > 1 ) { const lastChar = buff [ buff . length - 1 ] ; parts . push ( buff . substr ( 0 , buff . length - 1 ) ) ; buff = lastChar + char ; previusUpper = isUpper ; continue ; } } buff += char ; previusUpper = isUpper ; previousSplitter = isSplitter ; } parts . push ( buff ) ; return parts ; } export function upperFirst ( str ) { if ( ! str ) { return '' ; } return str [ 0 ] . toUpperCase ( ) + str . substr ( 1 ) ; } export function lowerFirst ( str ) { if ( ! str ) { return '' ; } return str [ 0 ] . toLocaleLowerCase ( ) + str . substr ( 1 ) ; } export function pascalCase ( str = '' ) { return ( Array . isArray ( str ) ? str : splitByCase ( str ) ) . map ( p => upperFirst ( p ) ) . join ( '' ) ; } export function camelCase ( str = '' ) { return lowerFirst ( pascalCase ( str ) ) ; } export function kebabCase ( str = '' , joiner = '-' ) { return ( Array . isArray ( str ) ? str : splitByCase ( str ) ) . map ( ( p = '' ) => p . toLocaleLowerCase ( ) ) . join ( joiner ) ; } export function snakeCase ( str = '' ) { return kebabCase ( str , '_' ) ; }