@@ -1553,6 +1553,8 @@ function addNumericSeparatorEnd(integerString) {
15531553 `${ result } ${ integerString . slice ( i ) } ` ;
15541554}
15551555
1556+ const remainingText = ( remaining ) => `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ;
1557+
15561558function formatNumber ( fn , number , numericSeparator ) {
15571559 if ( ! numericSeparator ) {
15581560 // 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) {
16801682 output . push ( ctx . stylize ( message , 'undefined' ) ) ;
16811683 }
16821684 } else if ( remaining > 0 ) {
1683- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1685+ output . push ( remainingText ( remaining ) ) ;
16841686 }
16851687 return output ;
16861688}
@@ -1718,7 +1720,7 @@ function formatArray(ctx, value, recurseTimes) {
17181720 output . push ( formatProperty ( ctx , value , recurseTimes , i , kArrayType ) ) ;
17191721 }
17201722 if ( remaining > 0 )
1721- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1723+ output . push ( remainingText ( remaining ) ) ;
17221724 return output ;
17231725}
17241726
@@ -1733,7 +1735,7 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
17331735 output [ i ] = elementFormatter ( ctx . stylize , value [ i ] , ctx . numericSeparator ) ;
17341736 }
17351737 if ( remaining > 0 ) {
1736- output [ maxLength ] = `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ;
1738+ output [ maxLength ] = remainingText ( remaining ) ;
17371739 }
17381740 if ( ctx . showHidden ) {
17391741 // .buffer goes last, it's not a primitive like the others.
@@ -1755,22 +1757,40 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
17551757}
17561758
17571759function formatSet ( value , ctx , ignored , recurseTimes ) {
1760+ const length = value . size ;
1761+ const maxLength = MathMin ( MathMax ( 0 , ctx . maxArrayLength ) , length ) ;
1762+ const remaining = length - maxLength ;
17581763 const output = [ ] ;
17591764 ctx . indentationLvl += 2 ;
1765+ let i = 0 ;
17601766 for ( const v of value ) {
1767+ if ( i >= maxLength ) break ;
17611768 ArrayPrototypePush ( output , formatValue ( ctx , v , recurseTimes ) ) ;
1769+ i ++ ;
1770+ }
1771+ if ( remaining > 0 ) {
1772+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
17621773 }
17631774 ctx . indentationLvl -= 2 ;
17641775 return output ;
17651776}
17661777
17671778function formatMap ( value , ctx , ignored , recurseTimes ) {
1779+ const length = value . size ;
1780+ const maxLength = MathMin ( MathMax ( 0 , ctx . maxArrayLength ) , length ) ;
1781+ const remaining = length - maxLength ;
17681782 const output = [ ] ;
17691783 ctx . indentationLvl += 2 ;
1784+ let i = 0 ;
17701785 for ( const { 0 : k , 1 : v } of value ) {
1786+ if ( i >= maxLength ) break ;
17711787 output . push (
17721788 `${ formatValue ( ctx , k , recurseTimes ) } => ${ formatValue ( ctx , v , recurseTimes ) } `
17731789 ) ;
1790+ i ++ ;
1791+ }
1792+ if ( remaining > 0 ) {
1793+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
17741794 }
17751795 ctx . indentationLvl -= 2 ;
17761796 return output ;
@@ -1793,8 +1813,7 @@ function formatSetIterInner(ctx, recurseTimes, entries, state) {
17931813 }
17941814 const remaining = entries . length - maxLength ;
17951815 if ( remaining > 0 ) {
1796- ArrayPrototypePush ( output ,
1797- `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ) ;
1816+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
17981817 }
17991818 return output ;
18001819}
@@ -1832,7 +1851,7 @@ function formatMapIterInner(ctx, recurseTimes, entries, state) {
18321851 }
18331852 ctx . indentationLvl -= 2 ;
18341853 if ( remaining > 0 ) {
1835- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1854+ output . push ( remainingText ( remaining ) ) ;
18361855 }
18371856 return output ;
18381857}
0 commit comments