Skip to content

Instantly share code, notes, and snippets.

@jason-s13r
Created April 10, 2013 01:58
Show Gist options
  • Save jason-s13r/5351139 to your computer and use it in GitHub Desktop.
Save jason-s13r/5351139 to your computer and use it in GitHub Desktop.
(function(_){
_.mixin({
wordCaps: function(s){
return s.toLowerCase()
.replace(/^[a-z]/, function(a){ return a.toUpperCase(); })
.replace(/ [a-z]/g, function(a){ return a.toUpperCase(); });
},
camelCase: function(s){
return _.wordCaps(s).replace(/ /g, '');
},
deCamelCase: function(s){
return _.wordCaps(s.replace(/([A-Z])/g, function(a){ return ' '+a; })
.replace(/(^ )|( $)/, ''));
},
lowerCamel: function(s){
return _.camelCase(s).charAt(0).toLowerCase() + _.camelCase(s).substring(1);
},
})
})(_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment