fixed camelCase function

Added check for empty word
This commit is contained in:
Aleh Kashnikau
2018-12-27 21:29:05 +03:00
committed by GitHub
parent 459ab71c45
commit 7432e01740
+9 -2
View File
@@ -359,7 +359,14 @@ class Utilities {
* @param {string} string The string to transform.
*/
camelCase(string){
return string.toLowerCase().trim().split(/[.\-_\s]/g).reduce((string, word) => string + word[0].toUpperCase() + word.slice(1));
return string
.toLowerCase()
.trim()
.split(/[.\-_\s]/g)
.reduce(
(string, word) =>
word.length ? string + word[0].toUpperCase() + word.slice(1) : string
);
};
/**
@@ -373,4 +380,4 @@ class Utilities {
}
}
export default Utilities;
export default Utilities;