File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " vue-truncate-filter" ,
3
- "version" : " 1.0 .0" ,
3
+ "version" : " 1.1 .0" ,
4
4
"description" : " A filter for VueJs to truncate string" ,
5
5
"main" : " vue-truncate.js" ,
6
6
"repository" : {
Original file line number Diff line number Diff line change 16
16
clamp = clamp || '...' ;
17
17
length = length || 30 ;
18
18
19
- return text . length > length
20
- ? text . slice ( 0 , length - clamp . length ) + clamp
21
- : text
22
- } ) ;
19
+ let truncateText = text . slice ( 0 , length - clamp . length )
20
+ let posLast = truncateText . length - 1
21
+
22
+ while ( truncateText [ posLast ] === ' ' || truncateText [ posLast ] === clamp [ 0 ] )
23
+ -- posLast
24
+
25
+ truncateText = truncateText . slice ( 0 , posLast + 1 )
26
+
27
+ return truncateText + ( text . length > length ? clamp : '' )
28
+ } ) ;
23
29
}
24
30
25
31
if ( typeof exports == "object" ) {
You can’t perform that action at this time.
0 commit comments