@@ -7,10 +7,16 @@ import { arrayToString } from "./array";
77 * Transform an object into a string.
88 */
99export 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 ) ) {
1112 return `Buffer.from(${ next ( value . toString ( "base64" ) ) } , 'base64')` ;
1213 }
1314
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+
1420 // Use the internal object string to select stringify method.
1521 const toString = OBJECT_TYPES [ Object . prototype . toString . call ( value ) ] ;
1622 return toString ? toString ( value , space , next , key ) : undefined ;
@@ -20,8 +26,6 @@ export const objectToString: ToString = (value, space, next, key) => {
2026 * Stringify an object of keys and values.
2127 */
2228const rawObjectToString : ToString = ( obj , indent , next , key ) => {
23- if ( obj === globalThis ) return globalToString ( obj , indent , next , key ) ;
24-
2529 const eol = indent ? "\n" : "" ;
2630 const space = indent ? " " : "" ;
2731
0 commit comments