Skip to content

Instantly share code, notes, and snippets.

@procarrera
Created August 25, 2021 18:31
Show Gist options
  • Save procarrera/c9583bd10e84d477d7aea4e870a3db85 to your computer and use it in GitHub Desktop.
Save procarrera/c9583bd10e84d477d7aea4e870a3db85 to your computer and use it in GitHub Desktop.
Transform CamelCase into separated words
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