Created
December 6, 2016 22:58
-
-
Save colelawrence/4d30c04cbb182db1c74c022fefa8deef 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
// kebab => capitallization | |
// open-up => OpenUp | |
// -a => A | |
function kebabToCaps(str) { | |
return String(str).replace(/(?:\-|^)(\w)?/g, (match, letter) => { | |
return letter ? letter.toUpperCase() : '' | |
}) | |
} | |
// capitallization => kebab | |
// OpenUp => open-up | |
// A => a | |
// URLShortener => url-shortener | |
function capsToKebab(str) { | |
return String(str || '') | |
.replace(/([A-Z0-9]+)([a-z])/g, '🤓$1$2') | |
.replace(/([A-Z0-9]+)([A-Z])/g, '$1🤓$2') | |
.replace(/^🤓+/g, '') | |
.replace(/(🤓)+/g, '-') | |
.toLowerCase() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment