Created
March 15, 2017 10:57
-
-
Save pascaliske/149e9bf6555c4d11317e144bfce16beb to your computer and use it in GitHub Desktop.
Convert dashed strings to camelcased strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ES5 | |
var camelize = function(string) { | |
return string.replace(/-([a-z])/g, function(match) { | |
return match[1].toUpperCase(); | |
}); | |
}; | |
// ES6 (short one-liner) | |
const camelize = string => string.replace(/-([a-z])/g, match => match[1].toUpperCase()); | |
// Example | |
console.log('some-dashed-string'); // => "some-dashed-string" | |
console.log(camelize('some-dashed-string')); // => "someDashedString" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment