@@ -1553,6 +1553,8 @@ function addNumericSeparatorEnd(integerString) {
1553
1553
`${ result } ${ integerString . slice ( i ) } ` ;
1554
1554
}
1555
1555
1556
+ const remainingText = ( remaining ) => `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ;
1557
+
1556
1558
function formatNumber ( fn , number , numericSeparator ) {
1557
1559
if ( ! numericSeparator ) {
1558
1560
// Format -0 as '-0'. Checking `number === -0` won't distinguish 0 from -0.
@@ -1679,7 +1681,7 @@ function formatSpecialArray(ctx, value, recurseTimes, maxLength, output, i) {
1679
1681
output . push ( ctx . stylize ( message , 'undefined' ) ) ;
1680
1682
}
1681
1683
} else if ( remaining > 0 ) {
1682
- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1684
+ output . push ( remainingText ( remaining ) ) ;
1683
1685
}
1684
1686
return output ;
1685
1687
}
@@ -1717,7 +1719,7 @@ function formatArray(ctx, value, recurseTimes) {
1717
1719
output . push ( formatProperty ( ctx , value , recurseTimes , i , kArrayType ) ) ;
1718
1720
}
1719
1721
if ( remaining > 0 )
1720
- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1722
+ output . push ( remainingText ( remaining ) ) ;
1721
1723
return output ;
1722
1724
}
1723
1725
@@ -1732,7 +1734,7 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
1732
1734
output [ i ] = elementFormatter ( ctx . stylize , value [ i ] , ctx . numericSeparator ) ;
1733
1735
}
1734
1736
if ( remaining > 0 ) {
1735
- output [ maxLength ] = `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ;
1737
+ output [ maxLength ] = remainingText ( remaining ) ;
1736
1738
}
1737
1739
if ( ctx . showHidden ) {
1738
1740
// .buffer goes last, it's not a primitive like the others.
@@ -1754,22 +1756,40 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
1754
1756
}
1755
1757
1756
1758
function formatSet ( value , ctx , ignored , recurseTimes ) {
1759
+ const length = value . size ;
1760
+ const maxLength = MathMin ( MathMax ( 0 , ctx . maxArrayLength ) , length ) ;
1761
+ const remaining = length - maxLength ;
1757
1762
const output = [ ] ;
1758
1763
ctx . indentationLvl += 2 ;
1764
+ let i = 0 ;
1759
1765
for ( const v of value ) {
1766
+ if ( i >= maxLength ) break ;
1760
1767
ArrayPrototypePush ( output , formatValue ( ctx , v , recurseTimes ) ) ;
1768
+ i ++ ;
1769
+ }
1770
+ if ( remaining > 0 ) {
1771
+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
1761
1772
}
1762
1773
ctx . indentationLvl -= 2 ;
1763
1774
return output ;
1764
1775
}
1765
1776
1766
1777
function formatMap ( value , ctx , ignored , recurseTimes ) {
1778
+ const length = value . size ;
1779
+ const maxLength = MathMin ( MathMax ( 0 , ctx . maxArrayLength ) , length ) ;
1780
+ const remaining = length - maxLength ;
1767
1781
const output = [ ] ;
1768
1782
ctx . indentationLvl += 2 ;
1783
+ let i = 0 ;
1769
1784
for ( const { 0 : k , 1 : v } of value ) {
1785
+ if ( i >= maxLength ) break ;
1770
1786
output . push (
1771
1787
`${ formatValue ( ctx , k , recurseTimes ) } => ${ formatValue ( ctx , v , recurseTimes ) } `
1772
1788
) ;
1789
+ i ++ ;
1790
+ }
1791
+ if ( remaining > 0 ) {
1792
+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
1773
1793
}
1774
1794
ctx . indentationLvl -= 2 ;
1775
1795
return output ;
@@ -1792,8 +1812,7 @@ function formatSetIterInner(ctx, recurseTimes, entries, state) {
1792
1812
}
1793
1813
const remaining = entries . length - maxLength ;
1794
1814
if ( remaining > 0 ) {
1795
- ArrayPrototypePush ( output ,
1796
- `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ) ;
1815
+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
1797
1816
}
1798
1817
return output ;
1799
1818
}
@@ -1831,7 +1850,7 @@ function formatMapIterInner(ctx, recurseTimes, entries, state) {
1831
1850
}
1832
1851
ctx . indentationLvl -= 2 ;
1833
1852
if ( remaining > 0 ) {
1834
- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1853
+ output . push ( remainingText ( remaining ) ) ;
1835
1854
}
1836
1855
return output ;
1837
1856
}
0 commit comments