Skip to content

Instantly share code, notes, and snippets.

@valentinvieriu
Created March 30, 2018 07:00
Show Gist options
  • Save valentinvieriu/22767ab51d36459176311b22f558106a to your computer and use it in GitHub Desktop.
Save valentinvieriu/22767ab51d36459176311b22f558106a to your computer and use it in GitHub Desktop.
Javascript convert camelcase to dash (hyphen)
/**
* 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