Skip to content

Instantly share code, notes, and snippets.

@jec006
Created September 3, 2013 20:34
Show Gist options
  • Save jec006/6429184 to your computer and use it in GitHub Desktop.
Save jec006/6429184 to your computer and use it in GitHub Desktop.
Turns a camelCase or Capital Case word into snake-case.
/**
* Take a camel case word and turn it into snake case
* i.e. layoutBlock to layout-block
*/
String.prototype.toSnakeCase = function() {
return this.replace(/ /g, '-').replace(/([a-z0-9])([A-Z0-9])/g, '$1-$2').toLowerCase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment