Created
April 27, 2018 17:34
-
-
Save dfmartin/b2d295a10673fc9dadabe773d9016038 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function snakeToCamel(str){ | |
return str.toLowerCase() | |
// Replaces any - or _ characters with a space | |
.replace( /[-_]+/g, ' ') | |
// Removes any non alphanumeric characters | |
.replace( /[^\w\s]/g, '') | |
// Uppercases the first character in each group immediately following a space | |
// (delimited by spaces) | |
.replace( / (.)/g, function($1) { return $1.toUpperCase(); }) | |
// Removes spaces | |
.replace( / /g, '' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment