Created
April 18, 2017 09:45
-
-
Save dtomasi/9327f704398be8d8ff5d0ab560b95641 to your computer and use it in GitHub Desktop.
CamelCase to kebab-case and backwards
This file contains hidden or 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
/** | |
* Convert Strings from camelCase to kebab-case | |
* @returns {string} | |
* @param input | |
*/ | |
static camelToKebab(input: string) { | |
return input.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | |
} | |
/** | |
* Convert Strings from kebab-case to camelCase | |
* @returns {string} | |
* @param input | |
*/ | |
static kebabToCamel(input: string) { | |
return input.replace(/-([a-z])/g, function (g) { | |
return g[1].toUpperCase(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment