Skip to content

Instantly share code, notes, and snippets.

@ja-k-e
Created May 28, 2015 18:03
Show Gist options
  • Select an option

  • Save ja-k-e/e1dd14facaee57f6ed1a to your computer and use it in GitHub Desktop.

Select an option

Save ja-k-e/e1dd14facaee57f6ed1a to your computer and use it in GitHub Desktop.
Angular Case Filter
// case:'upper', case:'lower', case:'title'
app.filter('case', function() {
return function(value, type) {
switch (type) {
case 'upper':
return value.toUpperCase();
case 'lower':
return value.toLowerCase();
case 'title':
return value.replace(/\w\S*/g, function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
default:
return value;
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment