Skip to content

Instantly share code, notes, and snippets.

@sleon-fmi
Created November 20, 2018 21:07
Show Gist options
  • Save sleon-fmi/f62ee21011750f5e0bd87065f3713488 to your computer and use it in GitHub Desktop.
Save sleon-fmi/f62ee21011750f5e0bd87065f3713488 to your computer and use it in GitHub Desktop.
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