-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
types: define Buffer #294
types: define Buffer #294
Conversation
(function(x) { | ||
return typeof Buffer !== 'undefined' && | ||
// eslint-disable-next-line no-undef | ||
Buffer.isBuffer (x); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following implementation is more elegant but less conducive to maintaining 100% branch coverage:
(typeof Buffer === 'undefined' ? K (false) : Buffer.isBuffer)
test/index.js
Outdated
(Buffer => { | ||
delete global.Buffer; | ||
try { | ||
eq (isBuffer (null)) (false); | ||
eq (isBuffer (Buffer.from ([1, 2, 3]))) (false); | ||
} finally { | ||
global.Buffer = Buffer; | ||
} | ||
}) (Buffer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete global.Buffer
removes our ability to reference Buffer
implicitly, so we must retain an explicit reference. (Buffer => …) (Buffer)
strikes me as more elegant than const Buffer_ = Buffer; …
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about const Buffer = global.Buffer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I did not consider { const Buffer = global.Buffer; … }
.
The code and approach look good to me. However, I would've probably separated any environment-specific types out into their own packages. I could imagine |
Providing separate packages for various environments is certainly an option worth considering. :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me. I'll leave it up to you to consider the separate packages idea. I guess we can always move to it in the future if maintaining node types in sanctuary-def becomes unwieldy or problematic for browsers.
3e3d816
to
25baaf0
Compare
This was recently requested by @jceb in sanctuary-js/sanctuary#575.