Created
June 18, 2013 11:25
-
-
Save vladimir-ivanov/5804622 to your computer and use it in GitHub Desktop.
AngularJs Truncate filter
This file contains 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
/*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, camelcase:false */ | |
/*globals | |
String: false | |
*/ | |
/*exported | |
TruncateFilter | |
*/ | |
var TruncateFilter = function () { | |
'use strict'; | |
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