Skip to content

Commit 3a485db

Browse files
committed
feat: Add fallback to Symbol.for(…)
1 parent 3b28eca commit 3a485db

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

index.js

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ var match = String.prototype.match;
1616
var bigIntValueOf = typeof BigInt === 'function' ? BigInt.prototype.valueOf : null;
1717

1818
var inspectCustom = require('./util.inspect').custom;
19+
/* eslint-disable no-restricted-properties */
20+
if (!inspectCustom && typeof Symbol === 'function' && typeof Symbol['for'] === 'function') {
21+
inspectCustom = Symbol['for']('nodejs.util.inspect.custom');
22+
}
23+
/* eslint-enable no-restricted-properties */
24+
1925
var inspectSymbol = inspectCustom && isSymbol(inspectCustom) ? inspectCustom : null;
2026

2127
module.exports = function inspect_(obj, options, depth, seen) {
@@ -143,6 +149,10 @@ module.exports = function inspect_(obj, options, depth, seen) {
143149
return String(obj);
144150
};
145151

152+
if (inspectSymbol) {
153+
module.exports.custom = inspectSymbol;
154+
}
155+
146156
function wrapQuotes(s, defaultStyle, opts) {
147157
var quoteChar = (opts.quoteStyle || defaultStyle) === 'double' ? '"' : "'";
148158
return quoteChar + s + quoteChar;

0 commit comments

Comments
 (0)