diff --git a/index.js b/index.js index 1394e53..ae5e23a 100644 --- a/index.js +++ b/index.js @@ -16,9 +16,13 @@ var match = String.prototype.match; var bigIntValueOf = typeof BigInt === 'function' ? BigInt.prototype.valueOf : null; var inspectCustom = require('./util.inspect').custom; +if (!inspectCustom && typeof Symbol === 'function' && typeof Symbol.for === 'function') { + inspectCustom = Symbol.for('nodejs.util.inspect.custom'); +} + var inspectSymbol = inspectCustom && isSymbol(inspectCustom) ? inspectCustom : null; -module.exports = function inspect_(obj, options, depth, seen) { +exports = module.exports = function inspect_(obj, options, depth, seen) { var opts = options || {}; if (has(opts, 'quoteStyle') && (opts.quoteStyle !== 'single' && opts.quoteStyle !== 'double')) { @@ -143,6 +147,10 @@ module.exports = function inspect_(obj, options, depth, seen) { return String(obj); }; +if (inspectSymbol) { + exports.custom = inspectSymbol; +} + function wrapQuotes(s, defaultStyle, opts) { var quoteChar = (opts.quoteStyle || defaultStyle) === 'double' ? '"' : "'"; return quoteChar + s + quoteChar;