@@ -8,13 +8,14 @@ var setSize = hasSet && setSizeDescriptor && typeof setSizeDescriptor.get === 'f
8
8
var setForEach = hasSet && Set . prototype . forEach ;
9
9
var booleanValueOf = Boolean . prototype . valueOf ;
10
10
var objectToString = Object . prototype . toString ;
11
+ var match = String . prototype . match ;
11
12
var bigIntValueOf = typeof BigInt === 'function' ? BigInt . prototype . valueOf : null ;
12
13
13
14
var inspectCustom = require ( './util.inspect' ) . custom ;
14
- var inspectSymbol = ( inspectCustom && isSymbol ( inspectCustom ) ) ? inspectCustom : null ;
15
+ var inspectSymbol = inspectCustom && isSymbol ( inspectCustom ) ? inspectCustom : null ;
15
16
16
- module . exports = function inspect_ ( obj , opts , depth , seen ) {
17
- if ( ! opts ) opts = { } ;
17
+ module . exports = function inspect_ ( obj , options , depth , seen ) {
18
+ var opts = options || { } ;
18
19
19
20
if ( has ( opts , 'quoteStyle' ) && ( opts . quoteStyle !== 'single' && opts . quoteStyle !== 'double' ) ) {
20
21
throw new TypeError ( 'option "quoteStyle" must be "single" or "double"' ) ;
@@ -34,27 +35,28 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
34
35
return inspectString ( obj , opts ) ;
35
36
}
36
37
if ( typeof obj === 'number' ) {
37
- if ( obj === 0 ) {
38
- return Infinity / obj > 0 ? '0' : '-0' ;
39
- }
40
- return String ( obj ) ;
38
+ if ( obj === 0 ) {
39
+ return Infinity / obj > 0 ? '0' : '-0' ;
40
+ }
41
+ return String ( obj ) ;
41
42
}
42
- if ( typeof obj === 'bigint' ) {
43
- return String ( obj ) + 'n' ;
43
+ if ( typeof obj === 'bigint' ) { // eslint-disable-line valid-typeof
44
+ return String ( obj ) + 'n' ;
44
45
}
45
46
46
47
var maxDepth = typeof opts . depth === 'undefined' ? 5 : opts . depth ;
47
- if ( typeof depth === 'undefined' ) depth = 0 ;
48
+ if ( typeof depth === 'undefined' ) { depth = 0 ; }
48
49
if ( depth >= maxDepth && maxDepth > 0 && typeof obj === 'object' ) {
49
50
return '[Object]' ;
50
51
}
51
52
52
- if ( typeof seen === 'undefined' ) seen = [ ] ;
53
- else if ( indexOf ( seen , obj ) >= 0 ) {
53
+ if ( typeof seen === 'undefined' ) {
54
+ seen = [ ] ;
55
+ } else if ( indexOf ( seen , obj ) >= 0 ) {
54
56
return '[Circular]' ;
55
57
}
56
58
57
- function inspect ( value , from ) {
59
+ function inspect ( value , from ) {
58
60
if ( from ) {
59
61
seen = seen . slice ( ) ;
60
62
seen . push ( from ) ;
@@ -77,17 +79,17 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
77
79
s += ' ' + attrs [ i ] . name + '=' + wrapQuotes ( quote ( attrs [ i ] . value ) , 'double' , opts ) ;
78
80
}
79
81
s += '>' ;
80
- if ( obj . childNodes && obj . childNodes . length ) s += '...' ;
82
+ if ( obj . childNodes && obj . childNodes . length ) { s += '...' ; }
81
83
s += '</' + String ( obj . nodeName ) . toLowerCase ( ) + '>' ;
82
84
return s ;
83
85
}
84
86
if ( isArray ( obj ) ) {
85
- if ( obj . length === 0 ) return '[]' ;
87
+ if ( obj . length === 0 ) { return '[]' ; }
86
88
return '[ ' + arrObjKeys ( obj , inspect ) . join ( ', ' ) + ' ]' ;
87
89
}
88
90
if ( isError ( obj ) ) {
89
91
var parts = arrObjKeys ( obj , inspect ) ;
90
- if ( parts . length === 0 ) return '[' + String ( obj ) + ']' ;
92
+ if ( parts . length === 0 ) { return '[' + String ( obj ) + ']' ; }
91
93
return '{ [' + String ( obj ) + '] ' + parts . join ( ', ' ) + ' }' ;
92
94
}
93
95
if ( typeof obj === 'object' ) {
@@ -98,18 +100,18 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
98
100
}
99
101
}
100
102
if ( isMap ( obj ) ) {
101
- var parts = [ ] ;
103
+ var mapParts = [ ] ;
102
104
mapForEach . call ( obj , function ( value , key ) {
103
- parts . push ( inspect ( key , obj ) + ' => ' + inspect ( value , obj ) ) ;
105
+ mapParts . push ( inspect ( key , obj ) + ' => ' + inspect ( value , obj ) ) ;
104
106
} ) ;
105
- return collectionOf ( 'Map' , mapSize . call ( obj ) , parts ) ;
107
+ return collectionOf ( 'Map' , mapSize . call ( obj ) , mapParts ) ;
106
108
}
107
109
if ( isSet ( obj ) ) {
108
- var parts = [ ] ;
109
- setForEach . call ( obj , function ( value ) {
110
- parts . push ( inspect ( value , obj ) ) ;
110
+ var setParts = [ ] ;
111
+ setForEach . call ( obj , function ( value ) {
112
+ setParts . push ( inspect ( value , obj ) ) ;
111
113
} ) ;
112
- return collectionOf ( 'Set' , setSize . call ( obj ) , parts ) ;
114
+ return collectionOf ( 'Set' , setSize . call ( obj ) , setParts ) ;
113
115
}
114
116
if ( isNumber ( obj ) ) {
115
117
return markBoxed ( inspect ( Number ( obj ) ) ) ;
@@ -125,55 +127,56 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
125
127
}
126
128
if ( ! isDate ( obj ) && ! isRegExp ( obj ) ) {
127
129
var xs = arrObjKeys ( obj , inspect ) ;
128
- if ( xs . length === 0 ) return '{}' ;
130
+ if ( xs . length === 0 ) { return '{}' ; }
129
131
return '{ ' + xs . join ( ', ' ) + ' }' ;
130
132
}
131
133
return String ( obj ) ;
132
134
} ;
133
135
134
- function wrapQuotes ( s , defaultStyle , opts ) {
136
+ function wrapQuotes ( s , defaultStyle , opts ) {
135
137
var quoteChar = ( opts . quoteStyle || defaultStyle ) === 'double' ? '"' : "'" ;
136
138
return quoteChar + s + quoteChar ;
137
139
}
138
140
139
- function quote ( s ) {
141
+ function quote ( s ) {
140
142
return String ( s ) . replace ( / " / g, '"' ) ;
141
143
}
142
144
143
- function isArray ( obj ) { return toStr ( obj ) === '[object Array]' ; }
144
- function isDate ( obj ) { return toStr ( obj ) === '[object Date]' ; }
145
- function isRegExp ( obj ) { return toStr ( obj ) === '[object RegExp]' ; }
146
- function isError ( obj ) { return toStr ( obj ) === '[object Error]' ; }
147
- function isSymbol ( obj ) { return toStr ( obj ) === '[object Symbol]' ; }
148
- function isString ( obj ) { return toStr ( obj ) === '[object String]' ; }
149
- function isNumber ( obj ) { return toStr ( obj ) === '[object Number]' ; }
150
- function isBigInt ( obj ) { return toStr ( obj ) === '[object BigInt]' ; }
151
- function isBoolean ( obj ) { return toStr ( obj ) === '[object Boolean]' ; }
145
+ function isArray ( obj ) { return toStr ( obj ) === '[object Array]' ; }
146
+ function isDate ( obj ) { return toStr ( obj ) === '[object Date]' ; }
147
+ function isRegExp ( obj ) { return toStr ( obj ) === '[object RegExp]' ; }
148
+ function isError ( obj ) { return toStr ( obj ) === '[object Error]' ; }
149
+ function isSymbol ( obj ) { return toStr ( obj ) === '[object Symbol]' ; }
150
+ function isString ( obj ) { return toStr ( obj ) === '[object String]' ; }
151
+ function isNumber ( obj ) { return toStr ( obj ) === '[object Number]' ; }
152
+ function isBigInt ( obj ) { return toStr ( obj ) === '[object BigInt]' ; }
153
+ function isBoolean ( obj ) { return toStr ( obj ) === '[object Boolean]' ; }
152
154
153
155
var hasOwn = Object . prototype . hasOwnProperty || function ( key ) { return key in this ; } ;
154
- function has ( obj , key ) {
156
+ function has ( obj , key ) {
155
157
return hasOwn . call ( obj , key ) ;
156
158
}
157
159
158
- function toStr ( obj ) {
160
+ function toStr ( obj ) {
159
161
return objectToString . call ( obj ) ;
160
162
}
161
163
162
- function nameOf ( f ) {
163
- if ( f . name ) return f . name ;
164
- var m = String ( f ) . match ( / ^ f u n c t i o n \s * ( [ \w $ ] + ) / ) ;
165
- if ( m ) return m [ 1 ] ;
164
+ function nameOf ( f ) {
165
+ if ( f . name ) { return f . name ; }
166
+ var m = match . call ( f , / ^ f u n c t i o n \s * ( [ \w $ ] + ) / ) ;
167
+ if ( m ) { return m [ 1 ] ; }
168
+ return null ;
166
169
}
167
170
168
- function indexOf ( xs , x ) {
169
- if ( xs . indexOf ) return xs . indexOf ( x ) ;
171
+ function indexOf ( xs , x ) {
172
+ if ( xs . indexOf ) { return xs . indexOf ( x ) ; }
170
173
for ( var i = 0 , l = xs . length ; i < l ; i ++ ) {
171
- if ( xs [ i ] === x ) return i ;
174
+ if ( xs [ i ] === x ) { return i ; }
172
175
}
173
176
return - 1 ;
174
177
}
175
178
176
- function isMap ( x ) {
179
+ function isMap ( x ) {
177
180
if ( ! mapSize ) {
178
181
return false ;
179
182
}
@@ -189,7 +192,7 @@ function isMap (x) {
189
192
return false ;
190
193
}
191
194
192
- function isSet ( x ) {
195
+ function isSet ( x ) {
193
196
if ( ! setSize ) {
194
197
return false ;
195
198
}
@@ -205,37 +208,38 @@ function isSet (x) {
205
208
return false ;
206
209
}
207
210
208
- function isElement ( x ) {
209
- if ( ! x || typeof x !== 'object' ) return false ;
211
+ function isElement ( x ) {
212
+ if ( ! x || typeof x !== 'object' ) { return false ; }
210
213
if ( typeof HTMLElement !== 'undefined' && x instanceof HTMLElement ) {
211
214
return true ;
212
215
}
213
- return typeof x . nodeName === 'string'
214
- && typeof x . getAttribute === 'function'
215
- ;
216
+ return typeof x . nodeName === 'string' && typeof x . getAttribute === 'function' ;
216
217
}
217
218
218
- function inspectString ( str , opts ) {
219
+ function inspectString ( str , opts ) {
220
+ // eslint-disable-next-line no-control-regex
219
221
var s = str . replace ( / ( [ ' \\ ] ) / g, '\\$1' ) . replace ( / [ \x00 - \x1f ] / g, lowbyte ) ;
220
222
return wrapQuotes ( s , 'single' , opts ) ;
221
223
}
222
224
223
- function lowbyte ( c ) {
225
+ function lowbyte ( c ) {
224
226
var n = c . charCodeAt ( 0 ) ;
225
- var x = { 8 : 'b' , 9 : 't' , 10 : 'n' , 12 : 'f' , 13 : 'r' } [ n ] ;
226
- if ( x ) return '\\' + x ;
227
+ var x = {
228
+ 8 : 'b' , 9 : 't' , 10 : 'n' , 12 : 'f' , 13 : 'r'
229
+ } [ n ] ;
230
+ if ( x ) { return '\\' + x ; }
227
231
return '\\x' + ( n < 0x10 ? '0' : '' ) + n . toString ( 16 ) ;
228
232
}
229
233
230
- function markBoxed ( str ) {
234
+ function markBoxed ( str ) {
231
235
return 'Object(' + str + ')' ;
232
236
}
233
237
234
- function collectionOf ( type , size , entries ) {
238
+ function collectionOf ( type , size , entries ) {
235
239
return type + ' (' + size + ') {' + entries . join ( ', ' ) + '}' ;
236
240
}
237
241
238
- function arrObjKeys ( obj , inspect ) {
242
+ function arrObjKeys ( obj , inspect ) {
239
243
var isArr = isArray ( obj ) ;
240
244
var xs = [ ] ;
241
245
if ( isArr ) {
@@ -244,10 +248,10 @@ function arrObjKeys (obj, inspect) {
244
248
xs [ i ] = has ( obj , i ) ? inspect ( obj [ i ] , obj ) : '' ;
245
249
}
246
250
}
247
- for ( var key in obj ) {
248
- if ( ! has ( obj , key ) ) continue ;
249
- if ( isArr && String ( Number ( key ) ) === key && key < obj . length ) continue ;
250
- if ( / [ ^ \w $ ] / . test ( key ) ) {
251
+ for ( var key in obj ) { // eslint-disable-line no-restricted-syntax
252
+ if ( ! has ( obj , key ) ) { continue ; } // eslint-disable-line no-restricted-syntax, no-continue
253
+ if ( isArr && String ( Number ( key ) ) === key && key < obj . length ) { continue ; } // eslint-disable-line no-restricted-syntax, no-continue
254
+ if ( ( / [ ^ \w $ ] / ) . test ( key ) ) {
251
255
xs . push ( inspect ( key , obj ) + ': ' + inspect ( obj [ key ] , obj ) ) ;
252
256
} else {
253
257
xs . push ( key + ': ' + inspect ( obj [ key ] , obj ) ) ;
0 commit comments