Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function spinalCase(str) {
  2.     var re = /[a-z][A-Z]|\_|\ /g;
  3.    // str = str[0].toLowerCase() + str.slice(1);
  4.  
  5.     str = str.replace(re, (match)=>{
  6.         switch(match){
  7.             case "_":
  8.             case " ":
  9.                 return "-";
  10.             default:
  11.                 [a,b] = match.split("");
  12.                 return a + "-" + b;
  13.         }
  14.     });
  15.     return str.toLowerCase();
  16. }
  17.  
  18. spinalCase('This Is Spinal Tap');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement