본문 바로가기

General

[arsclip, autohotkey] SNAKE_CASE to Camel_case

Convert SNAKE_CASE to Camel_case 로 변경

# arsclip

 

function main(clipboardStr) {
    var array = clipboardStr.split(";");
    // console.log(array.length);
    for (var i = 0; i < array.length; i++) {
        array[i] = lineCheck(array[i]);
    }
    var j = array.join(";");
    setClipboard(j);
}

function lineCheck(str) {
    var arr = str.split(" ");
    arr[arr.length - 1] = toCamelCase(arr[arr.length - 1]);
    return arr.length == 1 ? arr[0] : arr.join(" ");
}

function toCamelCase(str) {
    // Lower cases the string
    return str.toLowerCase()
        // Replaces any - or _ characters with a space
        .replace(/[-_]+/g, ' ')
        // Removes any non alphanumeric characters
        .replace(/[^\w\}\s]/g, '')
        // Uppercases the first character in each group immediately following a space
        // (delimited by spaces)
        .replace(/ (.)/g, function($1) {
            return $1.toUpperCase();
        })
        // Removes spaces
        .replace(/ /g, '');
}

 

=================================================================

# autohotkey

 

ConvertCamelCase()
{
    clipSaved := clipboard
    SendInput, ^c
    Sleep, 100
    SendInput, ^!+{f8}
    Sleep, 500

    SendInput, ^v
    Sleep, 100
    clipboard := clipSaved
}

^f8::ConvertCamelCase()

 

=================================================================

 

python 3.5 이상

 

def convert_camelCase(v):

    first, *others = v.split('_')

    return ''.join([first.lower(), *map(str.title, others)])

# end