Skip to content

Commit

Permalink
fix(utilities.js): Format string to lowercase before converting to ca…
Browse files Browse the repository at this point in the history
…mel case and assert the string is a string
  • Loading branch information
Ian Vieira committed Nov 26, 2017
1 parent 68cd565 commit 4522666
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
var _hyphenPattern = /-(.)/g;

function camelCase(string) {
return string.replace(_hyphenPattern, function(_, character) {
if (typeof string !== 'string') { // null is an object
throw new TypeError('First argument must be a string');
}
if(string.indexOf('-') < 0) {
return string;
}
return string.toLowerCase().replace(_hyphenPattern, function(_, character) {
return character.toUpperCase();
});
}
Expand Down

0 comments on commit 4522666

Please sign in to comment.