Created
March 30, 2018 07:00
-
-
Save valentinvieriu/22767ab51d36459176311b22f558106a to your computer and use it in GitHub Desktop.
Javascript convert camelcase to dash (hyphen)
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
/** | |
* camelCaseToDash('userId') => "user-id" | |
* camelCaseToDash('waitAMoment') => "wait-a-moment" | |
* camelCaseToDash('TurboPascal') => "turbo-pascal" | |
*/ | |
function camelCaseToDash (str) { | |
return str.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-').toLowerCase() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment