Skip to content

Commit 4522666

Browse files
author
Ian Vieira
committed
fix(utilities.js): Format string to lowercase before converting to camel case and assert the string is a string
1 parent 68cd565 commit 4522666

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/utilities.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
var _hyphenPattern = /-(.)/g;
1111

1212
function camelCase(string) {
13-
return string.replace(_hyphenPattern, function(_, character) {
13+
if (typeof string !== 'string') { // null is an object
14+
throw new TypeError('First argument must be a string');
15+
}
16+
if(string.indexOf('-') < 0) {
17+
return string;
18+
}
19+
return string.toLowerCase().replace(_hyphenPattern, function(_, character) {
1420
return character.toUpperCase();
1521
});
1622
}

0 commit comments

Comments
 (0)