Skip to content

Instantly share code, notes, and snippets.

@acedesigns
Created April 21, 2016 15:26
Show Gist options
  • Save acedesigns/9e064cff1600cb3f34695943885b871c to your computer and use it in GitHub Desktop.
Save acedesigns/9e064cff1600cb3f34695943885b871c to your computer and use it in GitHub Desktop.
/* =======================================================
* Custom Filters
* =======================================================
*/
(function() {
'use strict';
angular.module('app')
.filter('parag', 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) {
//Also remove . and , so its gives a cleaner result.
if (value.charAt(lastspace-1) == '.' || value.charAt(lastspace-1) == ',') {
lastspace = 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