Created
November 13, 2013 00:43
-
-
Save emh/7441569 to your computer and use it in GitHub Desktop.
I wanted to use a bunch of underscore.string (http://epeli.github.io/underscore.string/) functions as filters in an AngularJS project and rather than writing separate filters for each function I came up with this.
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
/** | |
* call titleize like: | |
* {{ expression | _str.'titleize' }} | |
* call truncate like: | |
* {{ expression | _str:'truncate':5:'...' }} | |
* etc. | |
*/ | |
app.filter('_str', function() { | |
return function(text, fn) { | |
var args = Array.prototype.slice.call(arguments, 2); | |
args.unshift(text); | |
return _.str[fn].apply(fn, args); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment