mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 10:07:48 +00:00
Simplify _.camelCase and add tests.
This commit is contained in:
@@ -6947,14 +6947,11 @@
|
||||
* _.camelCase('__hello_world__');
|
||||
* // => 'helloWorld'
|
||||
*/
|
||||
var camelCase = createCompounder(function(result, word, index, words) {
|
||||
var camelCase = createCompounder(function(result, word, index) {
|
||||
if (!index && reAllCaps.test(word)) {
|
||||
return result + word.toLowerCase();
|
||||
}
|
||||
var lastWord = index && words[index - 1],
|
||||
isCapped = index && !(index > 1 && words.length == 3 && (lastWord == 2 || lastWord == 4));
|
||||
|
||||
return result + (word.charAt(0)[isCapped ? 'toUpperCase' : 'toLowerCase']() + word.slice(1));
|
||||
return result + (word.charAt(0)[index ? 'toUpperCase' : 'toLowerCase']() + word.slice(1));
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user