@@ -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
}
@@ -1650,7 +1652,7 @@ function formatArray(ctx, value, recurseTimes) {
1650
1652
output . push ( formatProperty ( ctx , value , recurseTimes , i , kArrayType ) ) ;
1651
1653
}
1652
1654
if ( remaining > 0 )
1653
- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1655
+ output . push ( remainingText ( remaining ) ) ;
1654
1656
return output ;
1655
1657
}
1656
1658
@@ -1665,7 +1667,7 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
1665
1667
output [ i ] = elementFormatter ( ctx . stylize , value [ i ] , ctx . numericSeparator ) ;
1666
1668
}
1667
1669
if ( remaining > 0 ) {
1668
- output [ maxLength ] = `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ;
1670
+ output [ maxLength ] = remainingText ( remaining ) ;
1669
1671
}
1670
1672
if ( ctx . showHidden ) {
1671
1673
// .buffer goes last, it's not a primitive like the others.
@@ -1687,22 +1689,40 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
1687
1689
}
1688
1690
1689
1691
function formatSet ( value , ctx , ignored , recurseTimes ) {
1692
+ const length = value . size ;
1693
+ const maxLength = MathMin ( MathMax ( 0 , ctx . maxArrayLength ) , length ) ;
1694
+ const remaining = length - maxLength ;
1690
1695
const output = [ ] ;
1691
1696
ctx . indentationLvl += 2 ;
1697
+ let i = 0 ;
1692
1698
for ( const v of value ) {
1699
+ if ( i >= maxLength ) break ;
1693
1700
ArrayPrototypePush ( output , formatValue ( ctx , v , recurseTimes ) ) ;
1701
+ i ++ ;
1702
+ }
1703
+ if ( remaining > 0 ) {
1704
+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
1694
1705
}
1695
1706
ctx . indentationLvl -= 2 ;
1696
1707
return output ;
1697
1708
}
1698
1709
1699
1710
function formatMap ( value , ctx , ignored , recurseTimes ) {
1711
+ const length = value . size ;
1712
+ const maxLength = MathMin ( MathMax ( 0 , ctx . maxArrayLength ) , length ) ;
1713
+ const remaining = length - maxLength ;
1700
1714
const output = [ ] ;
1701
1715
ctx . indentationLvl += 2 ;
1716
+ let i = 0 ;
1702
1717
for ( const { 0 : k , 1 : v } of value ) {
1718
+ if ( i >= maxLength ) break ;
1703
1719
output . push (
1704
1720
`${ formatValue ( ctx , k , recurseTimes ) } => ${ formatValue ( ctx , v , recurseTimes ) } `
1705
1721
) ;
1722
+ i ++ ;
1723
+ }
1724
+ if ( remaining > 0 ) {
1725
+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
1706
1726
}
1707
1727
ctx . indentationLvl -= 2 ;
1708
1728
return output ;
@@ -1725,8 +1745,7 @@ function formatSetIterInner(ctx, recurseTimes, entries, state) {
1725
1745
}
1726
1746
const remaining = entries . length - maxLength ;
1727
1747
if ( remaining > 0 ) {
1728
- ArrayPrototypePush ( output ,
1729
- `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ) ;
1748
+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
1730
1749
}
1731
1750
return output ;
1732
1751
}
@@ -1764,7 +1783,7 @@ function formatMapIterInner(ctx, recurseTimes, entries, state) {
1764
1783
}
1765
1784
ctx . indentationLvl -= 2 ;
1766
1785
if ( remaining > 0 ) {
1767
- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1786
+ output . push ( remainingText ( remaining ) ) ;
1768
1787
}
1769
1788
return output ;
1770
1789
}
0 commit comments