SOURCE

function toUnderLine(param) {
    const camelToUnderLine = (param) => param.replace(/[A-Z]/g, (s) => '_' + s.toLowerCase())

    function loop(target, key, value) {
        toUnderLine(value)
        const newKey = camelToUnderLine(key)
        target[newKey] = value
        delete target[key]
        return target
    }
    if(typeof param === 'string') return camelToUnderLine(param)
    if (!param || typeof param !== 'object') return param
    if (typeof param === 'object') {
        if (Array.isArray(param)) {

        } else {
            // 对象
            for (let key in param) {
                param = loop(param, key, param[key])
            }
        }
    }
    return param
}
console.log(toUnderLine('aBbc'))
console 命令行工具 X clear

                    
>
console