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 87460ef
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 87460ef

Please sign in to comment.