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 11{
22 "name" : " vue-truncate-filter" ,
3- "version" : " 1.0 .0" ,
3+ "version" : " 1.1 .0" ,
44 "description" : " A filter for VueJs to truncate string" ,
55 "main" : " vue-truncate.js" ,
66 "repository" : {
Original file line number Diff line number Diff line change 1616 clamp = clamp || '...' ;
1717 length = length || 30 ;
1818
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+ } ) ;
2329 }
2430
2531 if ( typeof exports == "object" ) {
You can’t perform that action at this time.
0 commit comments