Skip to content

Commit

Permalink
truncate: fixes handling strings shorter than truncate length
Browse files Browse the repository at this point in the history
  • Loading branch information
amejiarosario committed Nov 4, 2015
1 parent 5d209c4 commit fe349c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module.exports = function(str, options) {
var separator = options.separator;
var omissionLength = omission.length;

if(str.length < length) return str;

if (separator) {
var words = str.split(separator);
var word = '';
Expand Down
5 changes: 5 additions & 0 deletions test/scripts/truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ describe('truncate', function() {
.should.eql('Once upon a time in a world...');
});

it('shorter string', function() {
truncate('Once upon')
.should.eql('Once upon');
});

it('truncate', function() {
truncate('Once upon a time in a world far far away', {length: 17})
.should.eql('Once upon a ti...');
Expand Down

0 comments on commit fe349c2

Please sign in to comment.