Skip to content

Commit

Permalink
fix bug: lack case
Browse files Browse the repository at this point in the history
  • Loading branch information
imcvampire committed Nov 14, 2016
1 parent 95dc1d9 commit 64e8b13
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-truncate-filter",
"version": "1.1.3",
"version": "1.1.4",
"description": "A filter for VueJs to truncate string",
"main": "vue-truncate.js",
"repository": {
Expand Down
5 changes: 4 additions & 1 deletion vue-truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
Vue.filter('truncate', function (text, length, clamp) {
clamp = clamp || '...';
length = length || 30;

if (text.length < length) return text;

var tcText = text.slice(0, length - clamp.length);
var last = tcText.length - 1;


while (last > 0 && tcText[last] !== ' ' && tcText[last] !== clamp[0])
last -= 1;

tcText = tcText.slice(0, last);

return tcText + (text.length > length ? clamp : '');
return tcText + clamp;
});
}

Expand Down

0 comments on commit 64e8b13

Please sign in to comment.