jonschlinkert / word-wrap

Wrap words to a specified length.
https://github.com/jonschlinkert
MIT License
193 stars 57 forks source link

Spaces not outputting as expected. #26

Open geozak opened 7 years ago

geozak commented 7 years ago

I ran this code in NodeJS console using npm version "^1.2.3"

var wrap = require('word-wrap');
var test = '1234 12345678';
var arguments = {width: 10, indent: ' ', newline: ' \n'};
var result = wrap(test, arguments);
result

In the following I will use '-' to represent a space.

I expected result to output -1234-\n-12345678 however the output of result was -1234--\n12345678.

Can someone explain why result has more and less spaces than I expected or confirm that this is a bug.

Thanks.

jonschlinkert commented 7 years ago

you're defining the newline with a leading space, it seems like the output is correct, since -\n would be appended to 1234- (also using - to represent a space)

geozak commented 7 years ago

Ah, so the space is considered part of the preceding string.

What about the lack of leading indent for the second line?

geozak commented 7 years ago

In index.js line 19 var newline = options.newline || '\n' + indent; when options.newline is used the indent is not appended.