Skip to content

Commit 64e8b13

Browse files
committed
fix bug: lack case
1 parent 95dc1d9 commit 64e8b13

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-truncate-filter",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "A filter for VueJs to truncate string",
55
"main": "vue-truncate.js",
66
"repository": {

vue-truncate.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@
1515
Vue.filter('truncate', function (text, length, clamp) {
1616
clamp = clamp || '...';
1717
length = length || 30;
18+
19+
if (text.length < length) return text;
1820

1921
var tcText = text.slice(0, length - clamp.length);
2022
var last = tcText.length - 1;
23+
2124

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

2528
tcText = tcText.slice(0, last);
2629

27-
return tcText + (text.length > length ? clamp : '');
30+
return tcText + clamp;
2831
});
2932
}
3033

0 commit comments

Comments
 (0)