字符串大小写转换通用函数
// 方法一
const bigCamel = (s) => {
let empty = " \t\r\n",
result = "";
for (let i = 0; i < s.length; i++) {
if(!empty.includes(s[i])) {
if (empty.includes(s[i-1]) || i === 0) {
result += s[i].toUpperCase()
} else {
result += s[i]
}
}
}
return result;
}
//方法二
const Camel = (str, opt) => {
return str.split(" ")
.filter(item => {
return item.length > 0
}).map(item => {
return opt === "lower" ?
item[0].toLowerCase() + item.substring(1) :
item[0].toUpperCase() + item.substring(1)
}).join(" ")
};