Skip to content

Instantly share code, notes, and snippets.

@vladimir-ivanov
Created May 17, 2013 08:47
Show Gist options
  • Save vladimir-ivanov/5597827 to your computer and use it in GitHub Desktop.
Save vladimir-ivanov/5597827 to your computer and use it in GitHub Desktop.
angular js truncate filter
/*jshint bitwise:true, camelcase:true, curly:true, eqeqeq:true, forin:true, latedef:true, newcap:true, noarg:true,
noempty:true, nonew:true, undef:true, unused:true, strict:true, browser:true */
/*globals
String: false;
*/
var TruncateFilter = function () {
return function (text, length, end) {
length = length || 55;
end = end || '...';
text = text || '';
if (text.length <= length || text.length - end.length <= length) {
return text;
} else {
text = String(text).substring(0, length - end.length) + end;
}
return text;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment