Skip to content

Commit

Permalink
superior algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
pexea12 committed Nov 11, 2016
1 parent 4871e00 commit 20f85bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 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.0.0",
"version": "1.1.0",
"description": "A filter for VueJs to truncate string",
"main": "vue-truncate.js",
"repository": {
Expand Down
14 changes: 10 additions & 4 deletions vue-truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
clamp = clamp || '...';
length = length || 30;

return text.length > length
? text.slice(0, length - clamp.length) + clamp
: text
});
let truncateText = text.slice(0, length - clamp.length)
let posLast = truncateText.length - 1

while (truncateText[posLast] === ' ' || truncateText[posLast] === clamp[0])
--posLast

truncateText = truncateText.slice(0, posLast + 1)

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

if (typeof exports == "object") {
Expand Down

0 comments on commit 20f85bb

Please sign in to comment.