@@ -7,10 +7,16 @@ import { arrayToString } from "./array";
7
7
* Transform an object into a string.
8
8
*/
9
9
export const objectToString : ToString = ( value , space , next , key ) => {
10
- if ( typeof ( Buffer as unknown ) === "function" && Buffer . isBuffer ( value ) ) {
10
+ // Support buffer in all environments.
11
+ if ( typeof Buffer === "function" && Buffer . isBuffer ( value ) ) {
11
12
return `Buffer.from(${ next ( value . toString ( "base64" ) ) } , 'base64')` ;
12
13
}
13
14
15
+ // Support `global` under test environments that don't print `[object global]`.
16
+ if ( typeof global === "object" && value === global ) {
17
+ return globalToString ( value , space , next , key ) ;
18
+ }
19
+
14
20
// Use the internal object string to select stringify method.
15
21
const toString = OBJECT_TYPES [ Object . prototype . toString . call ( value ) ] ;
16
22
return toString ? toString ( value , space , next , key ) : undefined ;
@@ -20,8 +26,6 @@ export const objectToString: ToString = (value, space, next, key) => {
20
26
* Stringify an object of keys and values.
21
27
*/
22
28
const rawObjectToString : ToString = ( obj , indent , next , key ) => {
23
- if ( obj === globalThis ) return globalToString ( obj , indent , next , key ) ;
24
-
25
29
const eol = indent ? "\n" : "" ;
26
30
const space = indent ? " " : "" ;
27
31
0 commit comments