Created
August 25, 2014 21:01
-
-
Save jeffskelton3/b39ed01c46fb414192fd to your computer and use it in GitHub Desktop.
a filter for summarizing large amounts of text down to a desired length
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
.filter('summaryText', function () { | |
return function (value, wordwise, max, tail) { | |
if (!value) return ''; | |
max = parseInt(max, 10); | |
if (!max) return value; | |
if (value.length <= max) return value; | |
value = value.substr(0, max); | |
if (wordwise) { | |
var lastspace = value.lastIndexOf(' '); | |
if (lastspace != -1) { | |
value = value.substr(0, lastspace); | |
} | |
} | |
return value + (tail || ' …'); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment