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.toLowerCase();
- }
- });
- return str.toLowerCase();
- }
- var x = spinalCase('This Is Spinal Tap');
- console.log(x);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement