Add checkOpen option#20
Conversation
| export function isWritableStream(stream) { | ||
| export function isWritableStream(stream, {checkOpen = true} = {}) { | ||
| return isStream(stream) | ||
| && stream.writable !== false |
There was a problem hiding this comment.
stream.writable and stream.readable are always booleans.
Is this a default you would have chosen if you made this package from scratch today? |
|
Probably not. The better behavior would probably be for I wanted to avoid any breaking change, but I was also suggesting making a major release with #21, for safety, so I could change the default value if you want? If you'd want to do a major release, I can also do a PR to update the supported Node.js range. Line 16 in 45e90c2 |
Yeah, then lets change the default.
I can handle that when releasing 👍 |
|
There is one catch though. The
However, those inherit all from a base class
Unfortunately, that base class does not define any So technically, one could inherit from this undocumented base class and miss those properties. But then the |
|
I thought of a solution to support the above edge case: if |
|
I implemented the solution above: ready for review 👍 |
Fixes #7.
The methods in this package check two different things:
There are times when one would want to check only
1.but not2.. For example:finished(),.pipe(), etc.) work fine with closed streams.1.and2.This PR adds a
checkOpenboolean option to toggle off that specific check.By default, it is
falseforisStream()andtruefor the others to keep backward compatibility. I.e. this is not a breaking change.