@@ -8,13 +8,14 @@ var setSize = hasSet && setSizeDescriptor && typeof setSizeDescriptor.get === 'f
88var setForEach = hasSet && Set . prototype . forEach ;
99var booleanValueOf = Boolean . prototype . valueOf ;
1010var objectToString = Object . prototype . toString ;
11+ var match = String . prototype . match ;
1112var bigIntValueOf = typeof BigInt === 'function' ? BigInt . prototype . valueOf : null ;
1213
1314var inspectCustom = require ( './util.inspect' ) . custom ;
14- var inspectSymbol = ( inspectCustom && isSymbol ( inspectCustom ) ) ? inspectCustom : null ;
15+ var inspectSymbol = inspectCustom && isSymbol ( inspectCustom ) ? inspectCustom : null ;
1516
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 || { } ;
1819
1920 if ( has ( opts , 'quoteStyle' ) && ( opts . quoteStyle !== 'single' && opts . quoteStyle !== 'double' ) ) {
2021 throw new TypeError ( 'option "quoteStyle" must be "single" or "double"' ) ;
@@ -34,27 +35,28 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
3435 return inspectString ( obj , opts ) ;
3536 }
3637 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 ) ;
4142 }
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' ;
4445 }
4546
4647 var maxDepth = typeof opts . depth === 'undefined' ? 5 : opts . depth ;
47- if ( typeof depth === 'undefined' ) depth = 0 ;
48+ if ( typeof depth === 'undefined' ) { depth = 0 ; }
4849 if ( depth >= maxDepth && maxDepth > 0 && typeof obj === 'object' ) {
4950 return '[Object]' ;
5051 }
5152
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 ) {
5456 return '[Circular]' ;
5557 }
5658
57- function inspect ( value , from ) {
59+ function inspect ( value , from ) {
5860 if ( from ) {
5961 seen = seen . slice ( ) ;
6062 seen . push ( from ) ;
@@ -77,17 +79,17 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
7779 s += ' ' + attrs [ i ] . name + '=' + wrapQuotes ( quote ( attrs [ i ] . value ) , 'double' , opts ) ;
7880 }
7981 s += '>' ;
80- if ( obj . childNodes && obj . childNodes . length ) s += '...' ;
82+ if ( obj . childNodes && obj . childNodes . length ) { s += '...' ; }
8183 s += '</' + String ( obj . nodeName ) . toLowerCase ( ) + '>' ;
8284 return s ;
8385 }
8486 if ( isArray ( obj ) ) {
85- if ( obj . length === 0 ) return '[]' ;
87+ if ( obj . length === 0 ) { return '[]' ; }
8688 return '[ ' + arrObjKeys ( obj , inspect ) . join ( ', ' ) + ' ]' ;
8789 }
8890 if ( isError ( obj ) ) {
8991 var parts = arrObjKeys ( obj , inspect ) ;
90- if ( parts . length === 0 ) return '[' + String ( obj ) + ']' ;
92+ if ( parts . length === 0 ) { return '[' + String ( obj ) + ']' ; }
9193 return '{ [' + String ( obj ) + '] ' + parts . join ( ', ' ) + ' }' ;
9294 }
9395 if ( typeof obj === 'object' ) {
@@ -98,18 +100,18 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
98100 }
99101 }
100102 if ( isMap ( obj ) ) {
101- var parts = [ ] ;
103+ var mapParts = [ ] ;
102104 mapForEach . call ( obj , function ( value , key ) {
103- parts . push ( inspect ( key , obj ) + ' => ' + inspect ( value , obj ) ) ;
105+ mapParts . push ( inspect ( key , obj ) + ' => ' + inspect ( value , obj ) ) ;
104106 } ) ;
105- return collectionOf ( 'Map' , mapSize . call ( obj ) , parts ) ;
107+ return collectionOf ( 'Map' , mapSize . call ( obj ) , mapParts ) ;
106108 }
107109 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 ) ) ;
111113 } ) ;
112- return collectionOf ( 'Set' , setSize . call ( obj ) , parts ) ;
114+ return collectionOf ( 'Set' , setSize . call ( obj ) , setParts ) ;
113115 }
114116 if ( isNumber ( obj ) ) {
115117 return markBoxed ( inspect ( Number ( obj ) ) ) ;
@@ -125,55 +127,56 @@ module.exports = function inspect_ (obj, opts, depth, seen) {
125127 }
126128 if ( ! isDate ( obj ) && ! isRegExp ( obj ) ) {
127129 var xs = arrObjKeys ( obj , inspect ) ;
128- if ( xs . length === 0 ) return '{}' ;
130+ if ( xs . length === 0 ) { return '{}' ; }
129131 return '{ ' + xs . join ( ', ' ) + ' }' ;
130132 }
131133 return String ( obj ) ;
132134} ;
133135
134- function wrapQuotes ( s , defaultStyle , opts ) {
136+ function wrapQuotes ( s , defaultStyle , opts ) {
135137 var quoteChar = ( opts . quoteStyle || defaultStyle ) === 'double' ? '"' : "'" ;
136138 return quoteChar + s + quoteChar ;
137139}
138140
139- function quote ( s ) {
141+ function quote ( s ) {
140142 return String ( s ) . replace ( / " / g, '"' ) ;
141143}
142144
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]' ; }
152154
153155var hasOwn = Object . prototype . hasOwnProperty || function ( key ) { return key in this ; } ;
154- function has ( obj , key ) {
156+ function has ( obj , key ) {
155157 return hasOwn . call ( obj , key ) ;
156158}
157159
158- function toStr ( obj ) {
160+ function toStr ( obj ) {
159161 return objectToString . call ( obj ) ;
160162}
161163
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 ;
166169}
167170
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 ) ; }
170173 for ( var i = 0 , l = xs . length ; i < l ; i ++ ) {
171- if ( xs [ i ] === x ) return i ;
174+ if ( xs [ i ] === x ) { return i ; }
172175 }
173176 return - 1 ;
174177}
175178
176- function isMap ( x ) {
179+ function isMap ( x ) {
177180 if ( ! mapSize ) {
178181 return false ;
179182 }
@@ -189,7 +192,7 @@ function isMap (x) {
189192 return false ;
190193}
191194
192- function isSet ( x ) {
195+ function isSet ( x ) {
193196 if ( ! setSize ) {
194197 return false ;
195198 }
@@ -205,37 +208,38 @@ function isSet (x) {
205208 return false ;
206209}
207210
208- function isElement ( x ) {
209- if ( ! x || typeof x !== 'object' ) return false ;
211+ function isElement ( x ) {
212+ if ( ! x || typeof x !== 'object' ) { return false ; }
210213 if ( typeof HTMLElement !== 'undefined' && x instanceof HTMLElement ) {
211214 return true ;
212215 }
213- return typeof x . nodeName === 'string'
214- && typeof x . getAttribute === 'function'
215- ;
216+ return typeof x . nodeName === 'string' && typeof x . getAttribute === 'function' ;
216217}
217218
218- function inspectString ( str , opts ) {
219+ function inspectString ( str , opts ) {
220+ // eslint-disable-next-line no-control-regex
219221 var s = str . replace ( / ( [ ' \\ ] ) / g, '\\$1' ) . replace ( / [ \x00 - \x1f ] / g, lowbyte ) ;
220222 return wrapQuotes ( s , 'single' , opts ) ;
221223}
222224
223- function lowbyte ( c ) {
225+ function lowbyte ( c ) {
224226 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 ; }
227231 return '\\x' + ( n < 0x10 ? '0' : '' ) + n . toString ( 16 ) ;
228232}
229233
230- function markBoxed ( str ) {
234+ function markBoxed ( str ) {
231235 return 'Object(' + str + ')' ;
232236}
233237
234- function collectionOf ( type , size , entries ) {
238+ function collectionOf ( type , size , entries ) {
235239 return type + ' (' + size + ') {' + entries . join ( ', ' ) + '}' ;
236240}
237241
238- function arrObjKeys ( obj , inspect ) {
242+ function arrObjKeys ( obj , inspect ) {
239243 var isArr = isArray ( obj ) ;
240244 var xs = [ ] ;
241245 if ( isArr ) {
@@ -244,10 +248,10 @@ function arrObjKeys (obj, inspect) {
244248 xs [ i ] = has ( obj , i ) ? inspect ( obj [ i ] , obj ) : '' ;
245249 }
246250 }
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 ) ) {
251255 xs . push ( inspect ( key , obj ) + ': ' + inspect ( obj [ key ] , obj ) ) ;
252256 } else {
253257 xs . push ( key + ': ' + inspect ( obj [ key ] , obj ) ) ;
0 commit comments