-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
provide custom inspect
behaviour in Node without using require
#303
Conversation
"engines": { | ||
"node": ">=10.12.0" | ||
}, |
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.
https://nodejs.org/en/blog/release/v10.12.0/:
- util
- The
util.inspect.custom
symbol is now defined in the global symbol registry asSymbol.for('nodejs.util.inspect.custom')
. util: use a shared symbol for util.inspect.custom nodejs/node#20857
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.
I followed along with the conversation you had with @dotnetCarpenter. LGTM! :)
wrapped.toString = always0 (typeSignature (typeInfo)); | ||
/* istanbul ignore else */ | ||
if ( | ||
typeof process !== 'undefined' && |
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.
@davidchambers This is a great addition to sanctuary-def - I will try it out on scrimba.com soon.
I only want to add that process !== 'undefined' && process != null
seems redundant.
process != null
should be enough.
null == undefined // true
null != undefined // false
The Abstract Equality Comparison Algorithm says in step 2: If x is null and y is undefined, return true. Step 3 is similar but with x
and y
switched.
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.
ah, you don't want to create a global variable called process
in non-node environments... Got it! Please disregard my comment ;)
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.
Also I think you pointed out in the chat that not guarding process
will throw an error....
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 expression is verbose, but I don't think any part of it can safely be omitted.
Fixes #300
@dotnetCarpenter and I came up with this solution last night on Gitter. :)
Assuming that CommonJS implies Node.js has caused people problems in several environments. It's exciting to be able to provide nice string representations of
def
-defined functions in the REPL without using the problematicrequire ('util')
!