@@ -146,6 +146,7 @@ const inspectDefaultOptions = ObjectSeal({
146
146
customInspect : true ,
147
147
showProxy : false ,
148
148
maxArrayLength : 100 ,
149
+ maxStringLength : Infinity ,
149
150
breakLength : 80 ,
150
151
compact : 3 ,
151
152
sorted : false ,
@@ -213,6 +214,7 @@ function getUserOptions(ctx) {
213
214
customInspect : ctx . customInspect ,
214
215
showProxy : ctx . showProxy ,
215
216
maxArrayLength : ctx . maxArrayLength ,
217
+ maxStringLength : ctx . maxStringLength ,
216
218
breakLength : ctx . breakLength ,
217
219
compact : ctx . compact ,
218
220
sorted : ctx . sorted ,
@@ -243,6 +245,7 @@ function inspect(value, opts) {
243
245
customInspect : inspectDefaultOptions . customInspect ,
244
246
showProxy : inspectDefaultOptions . showProxy ,
245
247
maxArrayLength : inspectDefaultOptions . maxArrayLength ,
248
+ maxStringLength : inspectDefaultOptions . maxStringLength ,
246
249
breakLength : inspectDefaultOptions . breakLength ,
247
250
compact : inspectDefaultOptions . compact ,
248
251
sorted : inspectDefaultOptions . sorted ,
@@ -280,6 +283,7 @@ function inspect(value, opts) {
280
283
}
281
284
if ( ctx . colors ) ctx . stylize = stylizeWithColor ;
282
285
if ( ctx . maxArrayLength === null ) ctx . maxArrayLength = Infinity ;
286
+ if ( ctx . maxStringLength === null ) ctx . maxStringLength = Infinity ;
283
287
return formatValue ( ctx , value , 0 ) ;
284
288
}
285
289
inspect . custom = customInspectSymbol ;
@@ -1296,6 +1300,12 @@ function formatBigInt(fn, value) {
1296
1300
1297
1301
function formatPrimitive ( fn , value , ctx ) {
1298
1302
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
+ }
1299
1309
if ( ctx . compact !== true &&
1300
1310
// TODO(BridgeAR): Add unicode support. Use the readline getStringWidth
1301
1311
// function.
@@ -1304,9 +1314,9 @@ function formatPrimitive(fn, value, ctx) {
1304
1314
return value
1305
1315
. split ( / (?< = \n ) / )
1306
1316
. map ( ( line ) => fn ( strEscape ( line ) , 'string' ) )
1307
- . join ( ` +\n${ ' ' . repeat ( ctx . indentationLvl + 2 ) } ` ) ;
1317
+ . join ( ` +\n${ ' ' . repeat ( ctx . indentationLvl + 2 ) } ` ) + trailer ;
1308
1318
}
1309
- return fn ( strEscape ( value ) , 'string' ) ;
1319
+ return fn ( strEscape ( value ) , 'string' ) + trailer ;
1310
1320
}
1311
1321
if ( typeof value === 'number' )
1312
1322
return formatNumber ( fn , value ) ;
0 commit comments