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