export class StringCaseUtil {
    
    //==================================================================================
    /** PascalCase / camelCase / UPPER_SKANE / lower_snake -> lower_snake
    *///================================================================================
    public static ToLowerSnake(word: string) {

        if(word == null || word.length === 0) return word;

        // 1. Small or Big Snake
        if(word.includes('_')) 
            return word.toLowerCase();

        // 2. Single Word
        if(word.match(/[A-Z]/) == null) 
            return word;

        // Pascal to Camel
        word = word[0].toLowerCase() + word.substring(1);
        
        // 3. Multiple Words, Camel
        return word.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
    }

    public static SnakeToCamel(snakeCase: string){
        return snakeCase.toLowerCase()
            .replace(/_+([a-z])/g, (m, $1) => $1.toUpperCase());
    };

    public static SnakeToPascal(snakeCase: string){
        const camel = snakeCase.toLowerCase()
            .replace(/_+([a-z])/g, (m, $1) => $1.toUpperCase());
        return camel[0].toUpperCase() + camel.substring(1);
    };
}