Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function spinalCase(str) {
- var re = /[a-z][A-Z]|\_|\ /g;
- // str = str[0].toLowerCase() + str.slice(1);
- str = str.replace(re, (match)=>{
- switch(match){
- case "_":
- case " ":
- return "-";
- default:
- [a,b] = match.split("");
- return a + "-" + b;
- }
- });
- return str.toLowerCase();
- }
- spinalCase('This Is Spinal Tap');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement