jonschlinkert / word-wrap

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

Question: how should this library handle undefined/null ? #20

Open callmemagnus opened 7 years ago

callmemagnus commented 7 years ago

This is more a question than an issue.

I was looking at the tests and wasn't able to answer the following question: how should word-wrap handle the nullor undefined case ?

I saw this in the index.js

if (str == null) {
    return str;
}

Don't you think this should return an empty string ?

jonschlinkert commented 7 years ago

Hmm, maybe. Typically I would throw a TypeError there, but I might have gone the "silent" route since this presumably is mostly used in command line apps. But I see you're point. Maybe we should do something like:

if (typeof str !== 'string') return '';

Thoughts?

callmemagnus commented 7 years ago

Would definitely make sense. As a consumer of your library, I would expect it to always return a string.