@@ -1487,6 +1487,8 @@ function addNumericSeparatorEnd(integerString) {
14871487 `${ result } ${ integerString . slice ( i ) } ` ;
14881488}
14891489
1490+ const remainingText = ( remaining ) => `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ;
1491+
14901492function formatNumber ( fn , number , numericSeparator ) {
14911493 if ( ! numericSeparator ) {
14921494 // 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) {
16131615 output . push ( ctx . stylize ( message , 'undefined' ) ) ;
16141616 }
16151617 } else if ( remaining > 0 ) {
1616- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1618+ output . push ( remainingText ( remaining ) ) ;
16171619 }
16181620 return output ;
16191621}
@@ -1651,7 +1653,7 @@ function formatArray(ctx, value, recurseTimes) {
16511653 output . push ( formatProperty ( ctx , value , recurseTimes , i , kArrayType ) ) ;
16521654 }
16531655 if ( remaining > 0 )
1654- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1656+ output . push ( remainingText ( remaining ) ) ;
16551657 return output ;
16561658}
16571659
@@ -1666,7 +1668,7 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
16661668 output [ i ] = elementFormatter ( ctx . stylize , value [ i ] , ctx . numericSeparator ) ;
16671669 }
16681670 if ( remaining > 0 ) {
1669- output [ maxLength ] = `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ;
1671+ output [ maxLength ] = remainingText ( remaining ) ;
16701672 }
16711673 if ( ctx . showHidden ) {
16721674 // .buffer goes last, it's not a primitive like the others.
@@ -1688,22 +1690,40 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
16881690}
16891691
16901692function formatSet ( value , ctx , ignored , recurseTimes ) {
1693+ const length = value . size ;
1694+ const maxLength = MathMin ( MathMax ( 0 , ctx . maxArrayLength ) , length ) ;
1695+ const remaining = length - maxLength ;
16911696 const output = [ ] ;
16921697 ctx . indentationLvl += 2 ;
1698+ let i = 0 ;
16931699 for ( const v of value ) {
1700+ if ( i >= maxLength ) break ;
16941701 ArrayPrototypePush ( output , formatValue ( ctx , v , recurseTimes ) ) ;
1702+ i ++ ;
1703+ }
1704+ if ( remaining > 0 ) {
1705+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
16951706 }
16961707 ctx . indentationLvl -= 2 ;
16971708 return output ;
16981709}
16991710
17001711function formatMap ( value , ctx , ignored , recurseTimes ) {
1712+ const length = value . size ;
1713+ const maxLength = MathMin ( MathMax ( 0 , ctx . maxArrayLength ) , length ) ;
1714+ const remaining = length - maxLength ;
17011715 const output = [ ] ;
17021716 ctx . indentationLvl += 2 ;
1717+ let i = 0 ;
17031718 for ( const { 0 : k , 1 : v } of value ) {
1719+ if ( i >= maxLength ) break ;
17041720 output . push (
17051721 `${ formatValue ( ctx , k , recurseTimes ) } => ${ formatValue ( ctx , v , recurseTimes ) } `
17061722 ) ;
1723+ i ++ ;
1724+ }
1725+ if ( remaining > 0 ) {
1726+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
17071727 }
17081728 ctx . indentationLvl -= 2 ;
17091729 return output ;
@@ -1726,8 +1746,7 @@ function formatSetIterInner(ctx, recurseTimes, entries, state) {
17261746 }
17271747 const remaining = entries . length - maxLength ;
17281748 if ( remaining > 0 ) {
1729- ArrayPrototypePush ( output ,
1730- `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ) ;
1749+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
17311750 }
17321751 return output ;
17331752}
@@ -1765,7 +1784,7 @@ function formatMapIterInner(ctx, recurseTimes, entries, state) {
17651784 }
17661785 ctx . indentationLvl -= 2 ;
17671786 if ( remaining > 0 ) {
1768- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1787+ output . push ( remainingText ( remaining ) ) ;
17691788 }
17701789 return output ;
17711790}
0 commit comments