File tree 3 files changed +24
-3
lines changed
3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -8,8 +8,9 @@ const encode = (obj, opt = {}) => {
8
8
opt . newline = opt . newline === true
9
9
opt . sort = opt . sort === true
10
10
opt . whitespace = opt . whitespace === true || opt . align === true
11
+ // The `typeof` check is required because accessing the `process` directly fails on browsers.
11
12
/* istanbul ignore next */
12
- opt . platform = opt . platform || process ? .platform
13
+ opt . platform = opt . platform || ( typeof process !== 'undefined' && process . platform )
13
14
opt . bracketedArray = opt . bracketedArray !== false
14
15
15
16
/* istanbul ignore next */
@@ -172,8 +173,8 @@ const decode = (str, opt = {}) => {
172
173
const remove = [ ]
173
174
for ( const k of Object . keys ( out ) ) {
174
175
if ( ! hasOwnProperty . call ( out , k ) ||
175
- typeof out [ k ] !== 'object' ||
176
- Array . isArray ( out [ k ] ) ) {
176
+ typeof out [ k ] !== 'object' ||
177
+ Array . isArray ( out [ k ] ) ) {
177
178
continue
178
179
}
179
180
Original file line number Diff line number Diff line change @@ -292,3 +292,13 @@ label = debug
292
292
value = 10
293
293
294
294
`
295
+
296
+ exports [ `test/foo.js TAP encode within browser context > must match snapshot 1` ] = `
297
+ [log]
298
+ type=file
299
+
300
+ [log.level]
301
+ label=debug
302
+ value=10
303
+
304
+ `
Original file line number Diff line number Diff line change @@ -84,3 +84,13 @@ test('encode with align and sort', function (t) {
84
84
t . matchSnapshot ( e )
85
85
t . end ( )
86
86
} )
87
+
88
+ test ( 'encode within browser context' , function ( t ) {
89
+ Object . defineProperty ( process , 'platform' , { value : undefined } )
90
+
91
+ const obj = { log : { type : 'file' , level : { label : 'debug' , value : 10 } } }
92
+ const e = i . encode ( obj )
93
+
94
+ t . matchSnapshot ( e )
95
+ t . end ( )
96
+ } )
You can’t perform that action at this time.
0 commit comments