Created
August 25, 2021 18:31
-
-
Save procarrera/c9583bd10e84d477d7aea4e870a3db85 to your computer and use it in GitHub Desktop.
Transform CamelCase into separated words
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
function decamelize(str, separator){ | |
separator = typeof separator === 'undefined' ? '_' : separator; | |
return str | |
.replace(/([a-z\d])([A-Z])/g, '$1' + separator + '$2') | |
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, '$1' + separator + '$2') | |
.toLowerCase(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment