Skip to content

Commit

Permalink
Merge pull request inloop#5 from 0xD34D/gh-pages
Browse files Browse the repository at this point in the history
Trim leading/trailing spaces from matches in wordwrap
  • Loading branch information
Juraj Novák committed Jan 16, 2015
2 parents 6252186 + 3b3124f commit 1649c10
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ function setMessage(text, type) {
}

function wordwrap( str, width, brk, cut ) {

brk = brk || '\n';
width = width || 75;
cut = cut || false;
Expand All @@ -344,6 +343,11 @@ function wordwrap( str, width, brk, cut ) {

var regex = '.{1,' +width+ '}(\\s|$)' + (cut ? '|.{' +width+ '}|.+$' : '|\\S+?(\\s|$)');

return str.match( new RegExp(regex, 'g') ).join( brk );
var matches = str.match( new RegExp(regex, 'g') );
// trim off leading/trailing spaces from the matched strings
for (i = 0; i < matches.length; i++) {
matches[i] = matches[i].trim();
}

return matches.join( brk );
}

0 comments on commit 1649c10

Please sign in to comment.