@@ -146,6 +146,7 @@ const inspectDefaultOptions = ObjectSeal({
146146 customInspect : true ,
147147 showProxy : false ,
148148 maxArrayLength : 100 ,
149+ maxStringLength : Infinity ,
149150 breakLength : 80 ,
150151 compact : 3 ,
151152 sorted : false ,
@@ -213,6 +214,7 @@ function getUserOptions(ctx) {
213214 customInspect : ctx . customInspect ,
214215 showProxy : ctx . showProxy ,
215216 maxArrayLength : ctx . maxArrayLength ,
217+ maxStringLength : ctx . maxStringLength ,
216218 breakLength : ctx . breakLength ,
217219 compact : ctx . compact ,
218220 sorted : ctx . sorted ,
@@ -243,6 +245,7 @@ function inspect(value, opts) {
243245 customInspect : inspectDefaultOptions . customInspect ,
244246 showProxy : inspectDefaultOptions . showProxy ,
245247 maxArrayLength : inspectDefaultOptions . maxArrayLength ,
248+ maxStringLength : inspectDefaultOptions . maxStringLength ,
246249 breakLength : inspectDefaultOptions . breakLength ,
247250 compact : inspectDefaultOptions . compact ,
248251 sorted : inspectDefaultOptions . sorted ,
@@ -280,6 +283,7 @@ function inspect(value, opts) {
280283 }
281284 if ( ctx . colors ) ctx . stylize = stylizeWithColor ;
282285 if ( ctx . maxArrayLength === null ) ctx . maxArrayLength = Infinity ;
286+ if ( ctx . maxStringLength === null ) ctx . maxStringLength = Infinity ;
283287 return formatValue ( ctx , value , 0 ) ;
284288}
285289inspect . custom = customInspectSymbol ;
@@ -1296,6 +1300,12 @@ function formatBigInt(fn, value) {
12961300
12971301function formatPrimitive ( fn , value , ctx ) {
12981302 if ( typeof value === 'string' ) {
1303+ let trailer = '' ;
1304+ if ( value . length > ctx . maxStringLength ) {
1305+ const remaining = value . length - ctx . maxStringLength ;
1306+ value = value . slice ( 0 , ctx . maxStringLength ) ;
1307+ trailer = `... ${ remaining } more character${ remaining > 1 ? 's' : '' } ` ;
1308+ }
12991309 if ( ctx . compact !== true &&
13001310 // TODO(BridgeAR): Add unicode support. Use the readline getStringWidth
13011311 // function.
@@ -1304,9 +1314,9 @@ function formatPrimitive(fn, value, ctx) {
13041314 return value
13051315 . split ( / (?< = \n ) / )
13061316 . map ( ( line ) => fn ( strEscape ( line ) , 'string' ) )
1307- . join ( ` +\n${ ' ' . repeat ( ctx . indentationLvl + 2 ) } ` ) ;
1317+ . join ( ` +\n${ ' ' . repeat ( ctx . indentationLvl + 2 ) } ` ) + trailer ;
13081318 }
1309- return fn ( strEscape ( value ) , 'string' ) ;
1319+ return fn ( strEscape ( value ) , 'string' ) + trailer ;
13101320 }
13111321 if ( typeof value === 'number' )
13121322 return formatNumber ( fn , value ) ;
0 commit comments