1. // 下划线转换驼峰
    2. function toHump(name) {
    3. return name.replace(/\_(\w)/g, function(all, letter){
    4. return letter.toUpperCase();
    5. });
    6. }
    7. // 驼峰转换下划线
    8. function toLine(name) {
    9. return name.replace(/([A-Z])/g,"_$1").toLowerCase();
    10. }
    11. // 测试
    12. let a = 'a_b2_345_c2345';
    13. console.log(toHump(a));
    14. let b = 'aBdaNf';
    15. console.log(toLine(b));