Skip to content

Instantly share code, notes, and snippets.

@aradnom
Created July 1, 2015 18:11
Show Gist options
  • Save aradnom/4ea9343148d2c4f476a0 to your computer and use it in GitHub Desktop.
Save aradnom/4ea9343148d2c4f476a0 to your computer and use it in GitHub Desktop.
Dashes to camelCase
/**
* Given a string-like-this, return a stringLikeThis.
*
* @param {String} str String to transform
*
* @return {String} Returns camelCased string
*/
function dashesToCamelCase ( str ) {
return str
.split( '-' )
.map( function ( chunk, index ) {
return index > 0
? chunk.substr( 0, 1 ).toUpperCase() + chunk.substr( 1, chunk.length )
: chunk; } )
.join( '' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment