Skip to content

Instantly share code, notes, and snippets.

@dfmartin
Created April 27, 2018 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfmartin/b2d295a10673fc9dadabe773d9016038 to your computer and use it in GitHub Desktop.
Save dfmartin/b2d295a10673fc9dadabe773d9016038 to your computer and use it in GitHub Desktop.
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