Created
July 17, 2017 19:12
-
-
Save jsjoeio/00703be708a0a5a7b3158cd091991f6d to your computer and use it in GitHub Desktop.
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
function spinalCase(str) { | |
//1. remove spaces, add - | |
//2. add - where capital letter | |
//3. remove underscore, add - | |
//4. remove spaces, add - | |
//5. remove | |
var newStr = str.replace(/ ([A-Z])/g, '-$1'); | |
newStr = newStr.replace(/\s|_/g, '-'); | |
return newStr.toLowerCase(); | |
} | |
spinalCase('thisIsSpinalTap'); | |
//This Is Spinal Tap | |
//thisIsSpinalTap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment