Skip to content

Commit 7ada44f

Browse files
committed
[New] add special handling for the global object
1 parent b453f6c commit 7ada44f

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

index.js

+7
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ module.exports = function inspect_(obj, options, depth, seen) {
239239
if (isString(obj)) {
240240
return markBoxed(inspect(String(obj)));
241241
}
242+
if (obj === global) {
243+
/* eslint-env browser */
244+
if (typeof window !== 'undefined') {
245+
return '{ [object Window] }';
246+
}
247+
return '{ [object global] }';
248+
}
242249
if (!isDate(obj) && !isRegExp(obj)) {
243250
var ys = arrObjKeys(obj, inspect);
244251
var isPlainObject = gPO ? gPO(obj) === Object.prototype : obj instanceof Object || obj.constructor === Object;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"eslint": "=8.8.0",
1616
"for-each": "^0.3.3",
1717
"functions-have-names": "^1.2.3",
18+
"globalthis": "^1.0.3",
1819
"has-tostringtag": "^1.0.0",
1920
"in-publish": "^2.0.1",
2021
"jackspeak": "=2.1.1",

test/global.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
3+
var inspect = require('../');
4+
5+
var test = require('tape');
6+
var globalThis = require('globalthis')();
7+
8+
test('global object', function (t) {
9+
/* eslint-env browser */
10+
var expected = typeof window === 'undefined' ? 'global' : 'Window';
11+
t.equal(
12+
inspect([globalThis]),
13+
'[ { [object ' + expected + '] } ]'
14+
);
15+
16+
t.end();
17+
});

0 commit comments

Comments
 (0)