Created
May 28, 2015 18:03
-
-
Save ja-k-e/e1dd14facaee57f6ed1a to your computer and use it in GitHub Desktop.
Angular Case Filter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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