From 3a485dba0020ca7804a8ed226c0e6171c7582e1e Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Sat, 1 Feb 2020 12:10: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, 10 insertions(+) diff --git a/index.js b/index.js index 1394e53..de59ae2 100644 --- a/index.js +++ b/index.js @@ -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'); +} +/* eslint-enable no-restricted-properties */ + var inspectSymbol = inspectCustom && isSymbol(inspectCustom) ? inspectCustom : null; module.exports = function inspect_(obj, options, depth, seen) { @@ -143,6 +149,10 @@ module.exports = function inspect_(obj, options, depth, seen) { return String(obj); }; +if (inspectSymbol) { + module.exports.custom = inspectSymbol; +} + function wrapQuotes(s, defaultStyle, opts) { var quoteChar = (opts.quoteStyle || defaultStyle) === 'double' ? '"' : "'"; return quoteChar + s + quoteChar;