Open Hongbusi opened 2 years ago
function toHump(str: string): string {
return str.replace(/\_(\w)/g, (_, letter) => {
return letter.toUpperCase();
})
}
function toHump(str) {
return str
.replace(/[_]/g, '/')
.split('/')
.reduce((previous, current) => previous + current.replace(/^\w/, (s) => s.toUpperCase()), '');
}
const compose = (...args: any[]) => values => args.reverse().reduce((prev, current)=> current(prev), values);
const strReplace = (str: string) => str.replace(/[_]/g, '');
const strToUpperCase = (str: string) => str.replace(/w/g, (strs, letter) => {
return strs.toUpperCase();
})
const flowRight = compose(strToUpperCase, strReplace);
console.log('flowRight: ', flowRight('hello_world'));
function trans(str:string):string {
if (!str.includes('_')) return str;
let flag:boolean = false;
let res:string = "";
for (let i = 0; i < str.length; i++) {
if (str[i] !== '_') {
res += (flag && i !== 1) ? str[i].toUpperCase() : str[i]
flag = false;
} else {
flag = true;
}
}
return res;
}