-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
feat: Add fallback to Symbol.for(…)
#30
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #30 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 2 2
Lines 206 210 +4
Branches 75 77 +2
=====================================
+ Hits 206 210 +4
Continue to review full report at Codecov.
|
87460ef
to
3a485db
Compare
@@ -143,6 +149,10 @@ module.exports = function inspect_(obj, options, depth, seen) { | |||
return String(obj); | |||
}; | |||
|
|||
if (inspectSymbol) { | |||
module.exports.custom = inspectSymbol; |
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'd prefer not to re-export this.
module.exports.custom = inspectSymbol; |
@@ -16,6 +16,12 @@ var match = String.prototype.match; | |||
var bigIntValueOf = typeof BigInt === 'function' ? BigInt.prototype.valueOf : null; | |||
|
|||
var inspectCustom = require('./util.inspect').custom; | |||
/* eslint-disable no-restricted-properties */ | |||
if (!inspectCustom && typeof Symbol === 'function' && typeof Symbol['for'] === 'function') { | |||
inspectCustom = Symbol['for']('nodejs.util.inspect.custom'); |
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.
This will mean that in the browser, however, a symbol will be registered and usable. it seems to me that util.inspect's custom symbol should only ever work in node.
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, this logic only helps in node >= 10.12; the dependency is still required for node 6.6-10.11, so i don’t see the value in this added complexity.
7363e8f
to
c2d7746
Compare
7ada44f
to
431bab2
Compare
Node 10.12 and newer registers the
util.inspect.custom
symbol asnodejs.util.inspect.custom
, making it possible to useSymbol.for('nodejs.util.inspect.custom')
to get the equivalentutil.inspect.custom
symbol without depending onutil
.