Skip to content

Commit

Permalink
feat: Add fallback to Symbol.for(…)
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Feb 1, 2020
1 parent 3b28eca commit 3a485db
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3a485db

Please sign in to comment.