1
2const toCamelCase = (str: string): string =>{
3 let charsLowerCase = str.toLowerCase().split('');
4 let camelCaseKey = '';
5 for (let pos = 0; pos < charsLowerCase.length; pos++) {
6 if (charsLowerCase[pos] === '_') {
7 let next = pos + 1;
8 charsLowerCase[next] = charsLowerCase[next].toUpperCase();
9 charsLowerCase.splice(pos, 1);
10 }
11 camelCaseKey += charsLowerCase[pos];
12 }
13 return camelCaseKey;
14}
15
16console.log(toCamelCase('hello_world'));
17// > helloWorld
1function convertSnakeToCamelSnake(obj: any){
2 let newTokens = []
3 if (obj) {
4 Object.keys(obj).forEach( key => {
5 newTokens = [] // Reset each loop
6 let tokens = key.split('_')
7 tokens.forEach( token => { newTokens.push(capitalizeFirstLetter(token)) }); // Capitalize first letter of each token
8 newTokens.join('') // Concatenate array indexes to string
9 });
10 }else{
11 console.log("Can not convert case of object:" + obj)
12 }
13 return newTokens
14}