Skip to content

Commit 02b34d8

Browse files
committed
Merge pull request #4 from scriptoLLC/fixing-newline-string
fixing new line issue
2 parents 1ebbc45 + 5980054 commit 02b34d8

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ module.exports = function(str, options) {
2121
var newline = options.newline || '\n' + indent;
2222

2323
var re = new RegExp('.{1,' + width + '}(\\s|$)|\\S+?(\\s|$)', 'g');
24-
var res = indent + str.match(re).join(newline);
24+
var lines = str.match(re) || [];
25+
var res = indent + lines.join(newline);
2526
if (options.trim === true) {
2627
res = res.replace(/[ \t]*$/gm, '');
2728
}

test.js

+4
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,9 @@ describe('wrap', function () {
3333
it('should trim trailing whitespace:', function () {
3434
wrap(str, {trim: true}).should.equal(' A project without documentation is like a project\n that doesn\'t exist. Verb solves this by making it\n dead simple to generate project documentation,\n using simple markdown templates, with zero\n configuration required.');
3535
});
36+
37+
it('should handle strings with just newlines', function () {
38+
wrap('\r\n', {indent: '\r\n', width: 18}).should.equal('\r\n');
39+
});
3640
});
3741

0 commit comments

Comments
 (0)