Skip to content

Commit 87460ef

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

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

index.js

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

1818
var inspectCustom = require('./util.inspect').custom;
19+
if (!inspectCustom && typeof Symbol === 'function' && typeof Symbol.for === 'function') {
20+
inspectCustom = Symbol.for('nodejs.util.inspect.custom');
21+
}
22+
1923
var inspectSymbol = inspectCustom && isSymbol(inspectCustom) ? inspectCustom : null;
2024

21-
module.exports = function inspect_(obj, options, depth, seen) {
25+
exports = module.exports = function inspect_(obj, options, depth, seen) {
2226
var opts = options || {};
2327

2428
if (has(opts, 'quoteStyle') && (opts.quoteStyle !== 'single' && opts.quoteStyle !== 'double')) {
@@ -143,6 +147,10 @@ module.exports = function inspect_(obj, options, depth, seen) {
143147
return String(obj);
144148
};
145149

150+
if (inspectSymbol) {
151+
exports.custom = inspectSymbol;
152+
}
153+
146154
function wrapQuotes(s, defaultStyle, opts) {
147155
var quoteChar = (opts.quoteStyle || defaultStyle) === 'double' ? '"' : "'";
148156
return quoteChar + s + quoteChar;

0 commit comments

Comments
 (0)