Skip to content

Commit 20cca77

Browse files
committed
[New] add support for util.inspect.custom, in node only.
1 parent 3b48fb2 commit 20cca77

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

index.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ var setForEach = hasSet && Set.prototype.forEach;
99
var booleanValueOf = Boolean.prototype.valueOf;
1010
var objectToString = Object.prototype.toString;
1111

12+
var inspectCustom = require('./util.inspect').custom;
13+
var inspectSymbol = (inspectCustom && isSymbol(inspectCustom)) ? inspectCustom : null;
14+
1215
module.exports = function inspect_ (obj, opts, depth, seen) {
1316
if (typeof obj === 'undefined') {
1417
return 'undefined';
@@ -78,8 +81,12 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
7881
if (parts.length === 0) return '[' + String(obj) + ']';
7982
return '{ [' + String(obj) + '] ' + parts.join(', ') + ' }';
8083
}
81-
if (typeof obj === 'object' && typeof obj.inspect === 'function') {
82-
return obj.inspect();
84+
if (typeof obj === 'object') {
85+
if (inspectSymbol && typeof obj[inspectSymbol] === 'function') {
86+
return obj[inspectSymbol]();
87+
} else if (typeof obj.inspect === 'function') {
88+
return obj.inspect();
89+
}
8390
}
8491
if (isMap(obj)) {
8592
var parts = [];

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,8 @@
4747
"email": "[email protected]",
4848
"url": "http://substack.net"
4949
},
50-
"license": "MIT"
50+
"license": "MIT",
51+
"browser": {
52+
"./util.inspect.js": false
53+
}
5154
}

util.inspect.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('util').inspect;

0 commit comments

Comments
 (0)