@@ -175,7 +175,7 @@ var parseObject = function (chain, val, options, valuesParsed) {
175
175
) {
176
176
obj = [ ] ;
177
177
obj [ index ] = leaf ;
178
- } else {
178
+ } else if ( cleanRoot !== '__proto__' ) {
179
179
obj [ cleanRoot ] = leaf ;
180
180
}
181
181
}
@@ -384,7 +384,7 @@ var stringify = function stringify(
384
384
var tmpSc = sideChannel ;
385
385
var step = 0 ;
386
386
var findFlag = false ;
387
- while ( ( tmpSc = tmpSc . get ( sentinel ) ) !== undefined && ! findFlag ) {
387
+ while ( ( tmpSc = tmpSc . get ( sentinel ) ) !== void undefined && ! findFlag ) {
388
388
// Where object last appeared in the ref tree
389
389
var pos = tmpSc . get ( object ) ;
390
390
step += 1 ;
@@ -446,7 +446,7 @@ var stringify = function stringify(
446
446
var objKeys ;
447
447
if ( generateArrayPrefix === 'comma' && isArray ( obj ) ) {
448
448
// we need to join elements in
449
- objKeys = [ { value : obj . length > 0 ? obj . join ( ',' ) || null : undefined } ] ;
449
+ objKeys = [ { value : obj . length > 0 ? obj . join ( ',' ) || null : void undefined } ] ;
450
450
} else if ( isArray ( filter ) ) {
451
451
objKeys = filter ;
452
452
} else {
@@ -456,7 +456,7 @@ var stringify = function stringify(
456
456
457
457
for ( var j = 0 ; j < objKeys . length ; ++ j ) {
458
458
var key = objKeys [ j ] ;
459
- var value = typeof key === 'object' && key . value !== undefined ? key . value : obj [ key ] ;
459
+ var value = typeof key === 'object' && typeof key . value !== ' undefined' ? key . value : obj [ key ] ;
460
460
461
461
if ( skipNulls && value === null ) {
462
462
continue ;
@@ -496,7 +496,7 @@ var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
496
496
return defaults ;
497
497
}
498
498
499
- if ( opts . encoder !== null && opts . encoder !== undefined && typeof opts . encoder !== 'function' ) {
499
+ if ( opts . encoder !== null && typeof opts . encoder !== ' undefined' && typeof opts . encoder !== 'function' ) {
500
500
throw new TypeError ( 'Encoder has to be a function.' ) ;
501
501
}
502
502
@@ -1419,11 +1419,24 @@ var weakRefDeref = hasWeakRef ? WeakRef.prototype.deref : null;
1419
1419
var booleanValueOf = Boolean . prototype . valueOf ;
1420
1420
var objectToString = Object . prototype . toString ;
1421
1421
var functionToString = Function . prototype . toString ;
1422
- var match = String . prototype . match ;
1422
+ var $match = String . prototype . match ;
1423
+ var $slice = String . prototype . slice ;
1424
+ var $replace = String . prototype . replace ;
1425
+ var $toUpperCase = String . prototype . toUpperCase ;
1426
+ var $toLowerCase = String . prototype . toLowerCase ;
1427
+ var $test = RegExp . prototype . test ;
1428
+ var $concat = Array . prototype . concat ;
1429
+ var $join = Array . prototype . join ;
1430
+ var $arrSlice = Array . prototype . slice ;
1431
+ var $floor = Math . floor ;
1423
1432
var bigIntValueOf = typeof BigInt === 'function' ? BigInt . prototype . valueOf : null ;
1424
1433
var gOPS = Object . getOwnPropertySymbols ;
1425
1434
var symToString = typeof Symbol === 'function' && typeof Symbol . iterator === 'symbol' ? Symbol . prototype . toString : null ;
1426
1435
var hasShammedSymbols = typeof Symbol === 'function' && typeof Symbol . iterator === 'object' ;
1436
+ // ie, `has-tostringtag/shams
1437
+ var toStringTag = typeof Symbol === 'function' && Symbol . toStringTag && ( typeof Symbol . toStringTag === hasShammedSymbols ? 'object' : 'symbol' )
1438
+ ? Symbol . toStringTag
1439
+ : null ;
1427
1440
var isEnumerable = Object . prototype . propertyIsEnumerable ;
1428
1441
1429
1442
var gPO = ( typeof Reflect === 'function' ? Reflect . getPrototypeOf : Object . getPrototypeOf ) || (
@@ -1434,9 +1447,30 @@ var gPO = (typeof Reflect === 'function' ? Reflect.getPrototypeOf : Object.getPr
1434
1447
: null
1435
1448
) ;
1436
1449
1450
+ function addNumericSeparator ( num , str ) {
1451
+ if (
1452
+ num === Infinity
1453
+ || num === - Infinity
1454
+ || num !== num
1455
+ || ( num && num > - 1000 && num < 1000 )
1456
+ || $test . call ( / e / , str )
1457
+ ) {
1458
+ return str ;
1459
+ }
1460
+ var sepRegex = / [ 0 - 9 ] (? = (?: [ 0 - 9 ] { 3 } ) + (? ! [ 0 - 9 ] ) ) / g;
1461
+ if ( typeof num === 'number' ) {
1462
+ var int = num < 0 ? - $floor ( - num ) : $floor ( num ) ; // trunc(num)
1463
+ if ( int !== num ) {
1464
+ var intStr = String ( int ) ;
1465
+ var dec = $slice . call ( str , intStr . length + 1 ) ;
1466
+ return $replace . call ( intStr , sepRegex , '$&_' ) + '.' + $replace . call ( $replace . call ( dec , / ( [ 0 - 9 ] { 3 } ) / g, '$&_' ) , / _ $ / , '' ) ;
1467
+ }
1468
+ }
1469
+ return $replace . call ( str , sepRegex , '$&_' ) ;
1470
+ }
1471
+
1437
1472
var inspectCustom = require ( './util.inspect' ) . custom ;
1438
1473
var inspectSymbol = inspectCustom && isSymbol ( inspectCustom ) ? inspectCustom : null ;
1439
- var toStringTag = typeof Symbol === 'function' && typeof Symbol . toStringTag !== 'undefined' ? Symbol . toStringTag : null ;
1440
1474
1441
1475
module . exports = function inspect_ ( obj , options , depth , seen ) {
1442
1476
var opts = options || { } ;
@@ -1463,8 +1497,12 @@ module.exports = function inspect_(obj, options, depth, seen) {
1463
1497
&& opts . indent !== '\t'
1464
1498
&& ! ( parseInt ( opts . indent , 10 ) === opts . indent && opts . indent > 0 )
1465
1499
) {
1466
- throw new TypeError ( 'options "indent" must be "\\t", an integer > 0, or `null`' ) ;
1500
+ throw new TypeError ( 'option "indent" must be "\\t", an integer > 0, or `null`' ) ;
1467
1501
}
1502
+ if ( has ( opts , 'numericSeparator' ) && typeof opts . numericSeparator !== 'boolean' ) {
1503
+ throw new TypeError ( 'option "numericSeparator", if provided, must be `true` or `false`' ) ;
1504
+ }
1505
+ var numericSeparator = opts . numericSeparator ;
1468
1506
1469
1507
if ( typeof obj === 'undefined' ) {
1470
1508
return 'undefined' ;
@@ -1483,10 +1521,12 @@ module.exports = function inspect_(obj, options, depth, seen) {
1483
1521
if ( obj === 0 ) {
1484
1522
return Infinity / obj > 0 ? '0' : '-0' ;
1485
1523
}
1486
- return String ( obj ) ;
1524
+ var str = String ( obj ) ;
1525
+ return numericSeparator ? addNumericSeparator ( obj , str ) : str ;
1487
1526
}
1488
1527
if ( typeof obj === 'bigint' ) {
1489
- return String ( obj ) + 'n' ;
1528
+ var bigIntStr = String ( obj ) + 'n' ;
1529
+ return numericSeparator ? addNumericSeparator ( obj , bigIntStr ) : bigIntStr ;
1490
1530
}
1491
1531
1492
1532
var maxDepth = typeof opts . depth === 'undefined' ? 5 : opts . depth ;
@@ -1505,7 +1545,7 @@ module.exports = function inspect_(obj, options, depth, seen) {
1505
1545
1506
1546
function inspect ( value , from , noIndent ) {
1507
1547
if ( from ) {
1508
- seen = seen . slice ( ) ;
1548
+ seen = $arrSlice . call ( seen ) ;
1509
1549
seen . push ( from ) ;
1510
1550
}
1511
1551
if ( noIndent ) {
@@ -1523,21 +1563,21 @@ module.exports = function inspect_(obj, options, depth, seen) {
1523
1563
if ( typeof obj === 'function' ) {
1524
1564
var name = nameOf ( obj ) ;
1525
1565
var keys = arrObjKeys ( obj , inspect ) ;
1526
- return '[Function' + ( name ? ': ' + name : ' (anonymous)' ) + ']' + ( keys . length > 0 ? ' { ' + keys . join ( ', ' ) + ' }' : '' ) ;
1566
+ return '[Function' + ( name ? ': ' + name : ' (anonymous)' ) + ']' + ( keys . length > 0 ? ' { ' + $ join. call ( keys , ', ' ) + ' }' : '' ) ;
1527
1567
}
1528
1568
if ( isSymbol ( obj ) ) {
1529
- var symString = hasShammedSymbols ? String ( obj ) . replace ( / ^ ( S y m b o l \( .* \) ) _ [ ^ ) ] * $ / , '$1' ) : symToString . call ( obj ) ;
1569
+ var symString = hasShammedSymbols ? $replace . call ( String ( obj ) , / ^ ( S y m b o l \( .* \) ) _ [ ^ ) ] * $ / , '$1' ) : symToString . call ( obj ) ;
1530
1570
return typeof obj === 'object' && ! hasShammedSymbols ? markBoxed ( symString ) : symString ;
1531
1571
}
1532
1572
if ( isElement ( obj ) ) {
1533
- var s = '<' + String ( obj . nodeName ) . toLowerCase ( ) ;
1573
+ var s = '<' + $toLowerCase . call ( String ( obj . nodeName ) ) ;
1534
1574
var attrs = obj . attributes || [ ] ;
1535
1575
for ( var i = 0 ; i < attrs . length ; i ++ ) {
1536
1576
s += ' ' + attrs [ i ] . name + '=' + wrapQuotes ( quote ( attrs [ i ] . value ) , 'double' , opts ) ;
1537
1577
}
1538
1578
s += '>' ;
1539
1579
if ( obj . childNodes && obj . childNodes . length ) { s += '...' ; }
1540
- s += '</' + String ( obj . nodeName ) . toLowerCase ( ) + '>' ;
1580
+ s += '</' + $toLowerCase . call ( String ( obj . nodeName ) ) + '>' ;
1541
1581
return s ;
1542
1582
}
1543
1583
if ( isArray ( obj ) ) {
@@ -1546,12 +1586,15 @@ module.exports = function inspect_(obj, options, depth, seen) {
1546
1586
if ( indent && ! singleLineValues ( xs ) ) {
1547
1587
return '[' + indentedJoin ( xs , indent ) + ']' ;
1548
1588
}
1549
- return '[ ' + xs . join ( ', ' ) + ' ]' ;
1589
+ return '[ ' + $ join. call ( xs , ', ' ) + ' ]' ;
1550
1590
}
1551
1591
if ( isError ( obj ) ) {
1552
1592
var parts = arrObjKeys ( obj , inspect ) ;
1593
+ if ( 'cause' in obj && ! isEnumerable . call ( obj , 'cause' ) ) {
1594
+ return '{ [' + String ( obj ) + '] ' + $join . call ( $concat . call ( '[cause]: ' + inspect ( obj . cause ) , parts ) , ', ' ) + ' }' ;
1595
+ }
1553
1596
if ( parts . length === 0 ) { return '[' + String ( obj ) + ']' ; }
1554
- return '{ [' + String ( obj ) + '] ' + parts . join ( ', ' ) + ' }' ;
1597
+ return '{ [' + String ( obj ) + '] ' + $ join. call ( parts , ', ' ) + ' }' ;
1555
1598
}
1556
1599
if ( typeof obj === 'object' && customInspect ) {
1557
1600
if ( inspectSymbol && typeof obj [ inspectSymbol ] === 'function' ) {
@@ -1599,14 +1642,14 @@ module.exports = function inspect_(obj, options, depth, seen) {
1599
1642
var ys = arrObjKeys ( obj , inspect ) ;
1600
1643
var isPlainObject = gPO ? gPO ( obj ) === Object . prototype : obj instanceof Object || obj . constructor === Object ;
1601
1644
var protoTag = obj instanceof Object ? '' : 'null prototype' ;
1602
- var stringTag = ! isPlainObject && toStringTag && Object ( obj ) === obj && toStringTag in obj ? toStr ( obj ) . slice ( 8 , - 1 ) : protoTag ? 'Object' : '' ;
1645
+ var stringTag = ! isPlainObject && toStringTag && Object ( obj ) === obj && toStringTag in obj ? $slice . call ( toStr ( obj ) , 8 , - 1 ) : protoTag ? 'Object' : '' ;
1603
1646
var constructorTag = isPlainObject || typeof obj . constructor !== 'function' ? '' : obj . constructor . name ? obj . constructor . name + ' ' : '' ;
1604
- var tag = constructorTag + ( stringTag || protoTag ? '[' + [ ] . concat ( stringTag || [ ] , protoTag || [ ] ) . join ( ': ' ) + '] ' : '' ) ;
1647
+ var tag = constructorTag + ( stringTag || protoTag ? '[' + $join . call ( $ concat. call ( [ ] , stringTag || [ ] , protoTag || [ ] ) , ': ' ) + '] ' : '' ) ;
1605
1648
if ( ys . length === 0 ) { return tag + '{}' ; }
1606
1649
if ( indent ) {
1607
1650
return tag + '{' + indentedJoin ( ys , indent ) + '}' ;
1608
1651
}
1609
- return tag + '{ ' + ys . join ( ', ' ) + ' }' ;
1652
+ return tag + '{ ' + $ join. call ( ys , ', ' ) + ' }' ;
1610
1653
}
1611
1654
return String ( obj ) ;
1612
1655
} ;
@@ -1617,7 +1660,7 @@ function wrapQuotes(s, defaultStyle, opts) {
1617
1660
}
1618
1661
1619
1662
function quote ( s ) {
1620
- return String ( s ) . replace ( / " / g, '"' ) ;
1663
+ return $replace . call ( String ( s ) , / " / g, '"' ) ;
1621
1664
}
1622
1665
1623
1666
function isArray ( obj ) { return toStr ( obj ) === '[object Array]' && ( ! toStringTag || ! ( typeof obj === 'object' && toStringTag in obj ) ) ; }
@@ -1668,7 +1711,7 @@ function toStr(obj) {
1668
1711
1669
1712
function nameOf ( f ) {
1670
1713
if ( f . name ) { return f . name ; }
1671
- var m = match . call ( functionToString . call ( f ) , / ^ f u n c t i o n \s * ( [ \w $ ] + ) / ) ;
1714
+ var m = $ match. call ( functionToString . call ( f ) , / ^ f u n c t i o n \s * ( [ \w $ ] + ) / ) ;
1672
1715
if ( m ) { return m [ 1 ] ; }
1673
1716
return null ;
1674
1717
}
@@ -1768,10 +1811,10 @@ function inspectString(str, opts) {
1768
1811
if ( str . length > opts . maxStringLength ) {
1769
1812
var remaining = str . length - opts . maxStringLength ;
1770
1813
var trailer = '... ' + remaining + ' more character' + ( remaining > 1 ? 's' : '' ) ;
1771
- return inspectString ( str . slice ( 0 , opts . maxStringLength ) , opts ) + trailer ;
1814
+ return inspectString ( $ slice. call ( str , 0 , opts . maxStringLength ) , opts ) + trailer ;
1772
1815
}
1773
1816
// eslint-disable-next-line no-control-regex
1774
- var s = str . replace ( / ( [ ' \\ ] ) / g, '\\$1' ) . replace ( / [ \x00 - \x1f ] / g, lowbyte ) ;
1817
+ var s = $replace . call ( $ replace. call ( str , / ( [ ' \\ ] ) / g, '\\$1' ) , / [ \x00 - \x1f ] / g, lowbyte ) ;
1775
1818
return wrapQuotes ( s , 'single' , opts ) ;
1776
1819
}
1777
1820
@@ -1785,7 +1828,7 @@ function lowbyte(c) {
1785
1828
13 : 'r'
1786
1829
} [ n ] ;
1787
1830
if ( x ) { return '\\' + x ; }
1788
- return '\\x' + ( n < 0x10 ? '0' : '' ) + n . toString ( 16 ) . toUpperCase ( ) ;
1831
+ return '\\x' + ( n < 0x10 ? '0' : '' ) + $toUpperCase . call ( n . toString ( 16 ) ) ;
1789
1832
}
1790
1833
1791
1834
function markBoxed ( str ) {
@@ -1797,7 +1840,7 @@ function weakCollectionOf(type) {
1797
1840
}
1798
1841
1799
1842
function collectionOf ( type , size , entries , indent ) {
1800
- var joinedEntries = indent ? indentedJoin ( entries , indent ) : entries . join ( ', ' ) ;
1843
+ var joinedEntries = indent ? indentedJoin ( entries , indent ) : $ join. call ( entries , ', ' ) ;
1801
1844
return type + ' (' + size + ') {' + joinedEntries + '}' ;
1802
1845
}
1803
1846
@@ -1815,20 +1858,20 @@ function getIndent(opts, depth) {
1815
1858
if ( opts . indent === '\t' ) {
1816
1859
baseIndent = '\t' ;
1817
1860
} else if ( typeof opts . indent === 'number' && opts . indent > 0 ) {
1818
- baseIndent = Array ( opts . indent + 1 ) . join ( ' ' ) ;
1861
+ baseIndent = $join . call ( Array ( opts . indent + 1 ) , ' ' ) ;
1819
1862
} else {
1820
1863
return null ;
1821
1864
}
1822
1865
return {
1823
1866
base : baseIndent ,
1824
- prev : Array ( depth + 1 ) . join ( baseIndent )
1867
+ prev : $join . call ( Array ( depth + 1 ) , baseIndent )
1825
1868
} ;
1826
1869
}
1827
1870
1828
1871
function indentedJoin ( xs , indent ) {
1829
1872
if ( xs . length === 0 ) { return '' ; }
1830
1873
var lineJoiner = '\n' + indent . prev + indent . base ;
1831
- return lineJoiner + xs . join ( ',' + lineJoiner ) + '\n' + indent . prev ;
1874
+ return lineJoiner + $ join. call ( xs , ',' + lineJoiner ) + '\n' + indent . prev ;
1832
1875
}
1833
1876
1834
1877
function arrObjKeys ( obj , inspect ) {
@@ -1855,7 +1898,7 @@ function arrObjKeys(obj, inspect) {
1855
1898
if ( hasShammedSymbols && symMap [ '$' + key ] instanceof Symbol ) {
1856
1899
// this is to prevent shammed Symbols, which are stored as strings, from being included in the string key section
1857
1900
continue ; // eslint-disable-line no-restricted-syntax, no-continue
1858
- } else if ( ( / [ ^ \w $ ] / ) . test ( key ) ) {
1901
+ } else if ( $test . call ( / [ ^ \w $ ] / , key ) ) {
1859
1902
xs . push ( inspect ( key , obj ) + ': ' + inspect ( obj [ key ] , obj ) ) ;
1860
1903
} else {
1861
1904
xs . push ( key + ': ' + inspect ( obj [ key ] , obj ) ) ;
0 commit comments