(str: string)
| 1 | export function camelCase(str: string): string { |
| 2 | if (!str) return ''; |
| 3 | |
| 4 | const words = str.split(' '); |
| 5 | |
| 6 | // do not convert strings that are already in camelCase format |
| 7 | if (words.length === 1 && /([a-z][A-Z])+/g.test(str)) { |
| 8 | return str; |
| 9 | } |
| 10 | |
| 11 | return words |
| 12 | .map(function (word, index) { |
| 13 | // if it is the first word, lowercase all the chars |
| 14 | if (index == 0) { |
| 15 | return word.toLowerCase(); |
| 16 | } |
| 17 | |
| 18 | // if it is not the first word only upper case the first char and lowercase the rest |
| 19 | return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); |
| 20 | }) |
| 21 | .join(''); |
| 22 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…