@@ -1487,6 +1487,8 @@ function addNumericSeparatorEnd(integerString) {
1487
1487
`${ result } ${ integerString . slice ( i ) } ` ;
1488
1488
}
1489
1489
1490
+ const remainingText = ( remaining ) => `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ;
1491
+
1490
1492
function formatNumber ( fn , number , numericSeparator ) {
1491
1493
if ( ! numericSeparator ) {
1492
1494
// Format -0 as '-0'. Checking `number === -0` won't distinguish 0 from -0.
@@ -1613,7 +1615,7 @@ function formatSpecialArray(ctx, value, recurseTimes, maxLength, output, i) {
1613
1615
output . push ( ctx . stylize ( message , 'undefined' ) ) ;
1614
1616
}
1615
1617
} else if ( remaining > 0 ) {
1616
- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1618
+ output . push ( remainingText ( remaining ) ) ;
1617
1619
}
1618
1620
return output ;
1619
1621
}
@@ -1651,7 +1653,7 @@ function formatArray(ctx, value, recurseTimes) {
1651
1653
output . push ( formatProperty ( ctx , value , recurseTimes , i , kArrayType ) ) ;
1652
1654
}
1653
1655
if ( remaining > 0 )
1654
- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1656
+ output . push ( remainingText ( remaining ) ) ;
1655
1657
return output ;
1656
1658
}
1657
1659
@@ -1666,7 +1668,7 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
1666
1668
output [ i ] = elementFormatter ( ctx . stylize , value [ i ] , ctx . numericSeparator ) ;
1667
1669
}
1668
1670
if ( remaining > 0 ) {
1669
- output [ maxLength ] = `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ;
1671
+ output [ maxLength ] = remainingText ( remaining ) ;
1670
1672
}
1671
1673
if ( ctx . showHidden ) {
1672
1674
// .buffer goes last, it's not a primitive like the others.
@@ -1688,22 +1690,40 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
1688
1690
}
1689
1691
1690
1692
function formatSet ( value , ctx , ignored , recurseTimes ) {
1693
+ const length = value . size ;
1694
+ const maxLength = MathMin ( MathMax ( 0 , ctx . maxArrayLength ) , length ) ;
1695
+ const remaining = length - maxLength ;
1691
1696
const output = [ ] ;
1692
1697
ctx . indentationLvl += 2 ;
1698
+ let i = 0 ;
1693
1699
for ( const v of value ) {
1700
+ if ( i >= maxLength ) break ;
1694
1701
ArrayPrototypePush ( output , formatValue ( ctx , v , recurseTimes ) ) ;
1702
+ i ++ ;
1703
+ }
1704
+ if ( remaining > 0 ) {
1705
+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
1695
1706
}
1696
1707
ctx . indentationLvl -= 2 ;
1697
1708
return output ;
1698
1709
}
1699
1710
1700
1711
function formatMap ( value , ctx , ignored , recurseTimes ) {
1712
+ const length = value . size ;
1713
+ const maxLength = MathMin ( MathMax ( 0 , ctx . maxArrayLength ) , length ) ;
1714
+ const remaining = length - maxLength ;
1701
1715
const output = [ ] ;
1702
1716
ctx . indentationLvl += 2 ;
1717
+ let i = 0 ;
1703
1718
for ( const { 0 : k , 1 : v } of value ) {
1719
+ if ( i >= maxLength ) break ;
1704
1720
output . push (
1705
1721
`${ formatValue ( ctx , k , recurseTimes ) } => ${ formatValue ( ctx , v , recurseTimes ) } `
1706
1722
) ;
1723
+ i ++ ;
1724
+ }
1725
+ if ( remaining > 0 ) {
1726
+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
1707
1727
}
1708
1728
ctx . indentationLvl -= 2 ;
1709
1729
return output ;
@@ -1726,8 +1746,7 @@ function formatSetIterInner(ctx, recurseTimes, entries, state) {
1726
1746
}
1727
1747
const remaining = entries . length - maxLength ;
1728
1748
if ( remaining > 0 ) {
1729
- ArrayPrototypePush ( output ,
1730
- `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ) ;
1749
+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
1731
1750
}
1732
1751
return output ;
1733
1752
}
@@ -1765,7 +1784,7 @@ function formatMapIterInner(ctx, recurseTimes, entries, state) {
1765
1784
}
1766
1785
ctx . indentationLvl -= 2 ;
1767
1786
if ( remaining > 0 ) {
1768
- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1787
+ output . push ( remainingText ( remaining ) ) ;
1769
1788
}
1770
1789
return output ;
1771
1790
}
0 commit comments