字符串大小写转换通用函数


// 方法一
const bigCamel = (s) => {
    let	empty = " 	
",
        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(" ")
};

原文地址:https://www.cnblogs.com/korea/p/11344087.html