provide custom inspect behaviour in Node without using require#303
provide custom inspect behaviour in Node without using require#303davidchambers merged 1 commit intomasterfrom
inspect behaviour in Node without using require#303Conversation
| "engines": { | ||
| "node": ">=10.12.0" | ||
| }, |
There was a problem hiding this comment.
https://nodejs.org/en/blog/release/v10.12.0/:
- util
- The
util.inspect.customsymbol 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
Avaq
left a comment
There was a problem hiding this comment.
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.
@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 // falseThe 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.
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.
Also I think you pointed out in the chat that not guarding process will throw an error....
There was a problem hiding this comment.
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')!