1.中划线转小驼峰命名
function transName1(str) {
let newStr = str.split('-').map((item, index) => {
if (index === 0) {
return item.toLowerCase();
} else {
item = item.split('').map((letter, i) => {
if (i == 0) {
letter = letter.toUpperCase();
}
return letter;
}).join('');
return item;
}
}).join('');
return newStr;
}
console.log(transName1('org-name'));
console.log(transName1('User-operate-log'));

function transName2(str) {
let newStr = str.split('-').map((item, index) => {
if (index !== 0) {
let first = item.substring(0, 1);
let rest = item.substring(1);
return first.toUpperCase() + rest;
} else {
return item.toLowerCase();
}
}).join('');
return newStr;
}
console.log(transName2('My-big-house'));

2.小驼峰转中划线命名
let str = 'aRedApple';
let t = str.replace(/[A-Z]/g, match => '-' + match.toLowerCase());
console.log(t);
