Created
December 23, 2015 14:27
-
-
Save SeanJM/50233e16793ad62e844a to your computer and use it in GitHub Desktop.
A function which 'kebab' cases a string
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 kebabCase(string) { | |
return string.split(/ |_|-/).join('-').split('').map(function (a) { | |
if (a.toUpperCase() === a && a !== '-') { | |
return '-' + a.toLowerCase(); | |
} | |
return a; | |
}).join('').toLowerCase(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment