Created
November 20, 2018 21:07
-
-
Save sleon-fmi/f62ee21011750f5e0bd87065f3713488 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
const kebabize = val => { | |
return val | |
.replace(/([a-z])([A-Z])/g, "$1-$2") | |
.replace(/\s+/g, "-") | |
.replace(/_{1,}/g, "-") | |
.toLowerCase(); | |
}; | |
const src = [ | |
"hocusPocus", | |
"HocusPocus", | |
"hocus_Pocus", | |
"hocus-pocus", | |
"hocus Pocus" | |
]; | |
const dst = src.map((x, i) => kebabize(x)); | |
for (let i = 0; i < src.length; i++) { | |
console.log(`${src[i]} ---> ${dst[i]}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment