@@ -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.
@@ -1679,7 +1681,7 @@ function formatSpecialArray(ctx, value, recurseTimes, maxLength, output, i) {
16791681 output . push ( ctx . stylize ( message , 'undefined' ) ) ;
16801682 }
16811683 } else if ( remaining > 0 ) {
1682- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1684+ output . push ( remainingText ( remaining ) ) ;
16831685 }
16841686 return output ;
16851687}
@@ -1717,7 +1719,7 @@ function formatArray(ctx, value, recurseTimes) {
17171719 output . push ( formatProperty ( ctx , value , recurseTimes , i , kArrayType ) ) ;
17181720 }
17191721 if ( remaining > 0 )
1720- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1722+ output . push ( remainingText ( remaining ) ) ;
17211723 return output ;
17221724}
17231725
@@ -1732,7 +1734,7 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
17321734 output [ i ] = elementFormatter ( ctx . stylize , value [ i ] , ctx . numericSeparator ) ;
17331735 }
17341736 if ( remaining > 0 ) {
1735- output [ maxLength ] = `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ;
1737+ output [ maxLength ] = remainingText ( remaining ) ;
17361738 }
17371739 if ( ctx . showHidden ) {
17381740 // .buffer goes last, it's not a primitive like the others.
@@ -1754,22 +1756,40 @@ function formatTypedArray(value, length, ctx, ignored, recurseTimes) {
17541756}
17551757
17561758function formatSet ( value , ctx , ignored , recurseTimes ) {
1759+ const length = value . size ;
1760+ const maxLength = MathMin ( MathMax ( 0 , ctx . maxArrayLength ) , length ) ;
1761+ const remaining = length - maxLength ;
17571762 const output = [ ] ;
17581763 ctx . indentationLvl += 2 ;
1764+ let i = 0 ;
17591765 for ( const v of value ) {
1766+ if ( i >= maxLength ) break ;
17601767 ArrayPrototypePush ( output , formatValue ( ctx , v , recurseTimes ) ) ;
1768+ i ++ ;
1769+ }
1770+ if ( remaining > 0 ) {
1771+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
17611772 }
17621773 ctx . indentationLvl -= 2 ;
17631774 return output ;
17641775}
17651776
17661777function formatMap ( value , ctx , ignored , recurseTimes ) {
1778+ const length = value . size ;
1779+ const maxLength = MathMin ( MathMax ( 0 , ctx . maxArrayLength ) , length ) ;
1780+ const remaining = length - maxLength ;
17671781 const output = [ ] ;
17681782 ctx . indentationLvl += 2 ;
1783+ let i = 0 ;
17691784 for ( const { 0 : k , 1 : v } of value ) {
1785+ if ( i >= maxLength ) break ;
17701786 output . push (
17711787 `${ formatValue ( ctx , k , recurseTimes ) } => ${ formatValue ( ctx , v , recurseTimes ) } `
17721788 ) ;
1789+ i ++ ;
1790+ }
1791+ if ( remaining > 0 ) {
1792+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
17731793 }
17741794 ctx . indentationLvl -= 2 ;
17751795 return output ;
@@ -1792,8 +1812,7 @@ function formatSetIterInner(ctx, recurseTimes, entries, state) {
17921812 }
17931813 const remaining = entries . length - maxLength ;
17941814 if ( remaining > 0 ) {
1795- ArrayPrototypePush ( output ,
1796- `... ${ remaining } more item${ remaining > 1 ? 's' : '' } ` ) ;
1815+ ArrayPrototypePush ( output , remainingText ( remaining ) ) ;
17971816 }
17981817 return output ;
17991818}
@@ -1831,7 +1850,7 @@ function formatMapIterInner(ctx, recurseTimes, entries, state) {
18311850 }
18321851 ctx . indentationLvl -= 2 ;
18331852 if ( remaining > 0 ) {
1834- output . push ( `... ${ remaining } more item ${ remaining > 1 ? 's' : '' } ` ) ;
1853+ output . push ( remainingText ( remaining ) ) ;
18351854 }
18361855 return output ;
18371856}
0 commit comments