From 87460ef1af0e97a5ff68cb0f6b36a31f7ff5b1ae Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Sat, 1 Feb 2020 11:40:00 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Add=C2=A0fallback=20to=C2=A0`Symbol.for?= =?UTF-8?q?(=E2=80=A6)`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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;